package cqrtplm.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hustcad.plm.basic.log.LogEventEnum;
import com.hustcad.plm.basic.log.TyplmLogger;
import com.hustcad.plm.basic.util.TyplmEntityBaseUtil;
import com.hustcad.plm.basic.util.TyplmLoggerUtil;
import com.hustcad.plm.pdm.audit.util.TyplmAuditLogUtil;
import com.hustcad.plm.pdm.basedrule.dto.TyplmBaseRuleBoundedObjDTO;
import com.hustcad.plm.pdm.basedrule.service.TyplmBasedRuleService;
import com.hustcad.plm.pdm.classification.service.TyplmClassificationService;
import com.hustcad.plm.pdm.code.model.dto.codemanagement.TyplmSegmentCodeConditionDTO;
import com.hustcad.plm.pdm.code.model.vo.codemanagement.segmentcode.TyplmSegmentCodeRuleVO;
import com.hustcad.plm.pdm.code.service.codemanagement.TyplmSegmentCodeService;
import com.hustcad.plm.pdm.common.model.dto.BasicObjectDTO;
import com.hustcad.plm.pdm.common.model.vo.BusinessObjectVO;
import com.hustcad.plm.pdm.common.model.vo.iteration.CommonIteratorVO;
import com.hustcad.plm.pdm.common.util.CommonUtil;
import com.hustcad.plm.pdm.doc.service.TyplmDocumentService;
import com.hustcad.plm.pdm.doc.vo.DocDetails;
import com.hustcad.plm.pdm.ec.mapper.TyplmChgNoticeActivityLinkMapper;
import com.hustcad.plm.pdm.ec.module.dto.*;
import com.hustcad.plm.pdm.ec.module.vo.*;
import com.hustcad.plm.pdm.ec.service.*;
import com.hustcad.plm.pdm.enumeration.service.TyplmEnumerationService;
import com.hustcad.plm.pdm.flowbusiness.model.entity.*;
import com.hustcad.plm.pdm.flowbusiness.service.TyplmFlowChangeRequestViewService;
import com.hustcad.plm.pdm.flowbusiness.service.TyplmFlowChgFormNoticeViewService;
import com.hustcad.plm.pdm.form.model.vo.FormTemplateVO;
import com.hustcad.plm.pdm.form.service.TyplmFormTemplateService;
import com.hustcad.plm.pdm.iba.model.dto.SaveObjIBADTO;
import com.hustcad.plm.pdm.iba.service.TyplmAttributeValueService;
import com.hustcad.plm.pdm.iteration.service.TyplmIterationService;
import com.hustcad.plm.pdm.lifestage.model.dto.EntityLifeCycleDTO;
import com.hustcad.plm.pdm.lifestage.model.dto.TyLifecycleStateDTO;
import com.hustcad.plm.pdm.lifestage.model.dto.TyLifecycleTemplateAndStatusDTO;
import com.hustcad.plm.pdm.lifestage.model.vo.TyLifecycleTemplateAllVO;
import com.hustcad.plm.pdm.lifestage.service.TyplmCommonLifecycleService;
import com.hustcad.plm.pdm.lifestage.service.TyplmLifecycleTemplateService;
import com.hustcad.plm.pdm.middle.partbom.service.TyplmPdmPartService;
import com.hustcad.plm.pdm.modeling.model.dto.TyplmGeneralOperationDTO;
import com.hustcad.plm.pdm.mpm.service.TyplmTechnologyWorkFlowService;
import com.hustcad.plm.pdm.mpmlink.service.TyplmMpmWorkFlowAdaptationService;
import com.hustcad.plm.pdm.partbom.dto.PartBomTree;
import com.hustcad.plm.pdm.partbom.dto.PartUsageLink;
import com.hustcad.plm.pdm.partbom.service.TyplmPartRelObjectService;
import com.hustcad.plm.pdm.partbom.service.TyplmPartService;
import com.hustcad.plm.pdm.partbom.vo.PartBomTreeByFilterVO;
import com.hustcad.plm.pdm.partbom.vo.PartDetailsVO;
import com.hustcad.plm.pdm.type.service.TyplmTypeService;
import com.hustcad.plm.pdm.user.model.dto.PdmUserDTO;
import com.hustcad.plm.pdm.user.service.TyplmOrgService;
import com.hustcad.plm.pdm.user.service.TyplmPrincipalService;
import com.hustcad.plm.pdm.user.service.TyplmUserService;
import com.hustcad.plm.pdm.workflow.model.entity.FlowTaskRecord;
import com.hustcad.plm.pdm.workflow.model.entity.UserTaskDTO;
import com.hustcad.plm.pdm.workflow.model.entity.WorkFlow;
import com.hustcad.plm.pdm.workflow.model.entity.WorkFlowContainerView;
import com.hustcad.plm.pdm.workflow.service.*;
import com.hustcad.plm.workspace.dto.ObjNumberDTO;
import com.hustcad.plm.workspace.service.TyPlmWorkspaceObjectService;
import com.hustcad.plm.workspace.vo.ObjNumberErrorVO;
import com.ty.basic.common.ITyIterated;
import com.ty.basic.common.ITyLifeCycleManaged;
import com.ty.basic.constant.TableTypeConstrant;
import com.ty.basic.dto.constraint.IbaDTO;
import com.ty.basic.dto.lifecycle.LifeCycleTemplateConvertDTO;
import com.ty.basic.dto.lifecycle.LifeCycleTemplateConvertQueryDTO;
import com.ty.basic.entity.CTyEntityBaseDO;
import com.ty.basic.entity.IdentifierEntity;
import com.ty.basic.entity.PrincipalEntity;
import com.ty.basic.entity.audit.AuditLogDO;
import com.ty.basic.entity.change.ChgActRecordLinkDO;
import com.ty.basic.entity.change.ChgActRelDataLinkDO;
import com.ty.basic.entity.change.ChgActivityDO;
import com.ty.basic.entity.change.ChgNoticeDO;
import com.ty.basic.entity.org.OrgDO;
import com.ty.basic.entity.org.UserDO;
import com.ty.basic.entity.part.PartDO;
import com.ty.basic.entity.type.ClassificationDO;
import com.ty.basic.exception.message.SystemErrorCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.ResponseCodeEnum;
import com.ty.basic.handler.exceptionhandler.exception.TyException;
import com.ty.basic.response.ResponseResult;
import com.ty.basic.service.snow.SnowflakeIdComponent;
import com.ty.basic.session.TyAccountContext;
import com.ty.basic.utils.ArgumentUtils;
import cqrtplm.common.CommonService;
import cqrtplm.constant.RTErrorCodeEnum;
import cqrtplm.constant.RTPlmConstant;
import cqrtplm.dto.RtCfgBOMAndStatusInfoDTO;
import cqrtplm.dto.RtCfgStatusDTO;
import cqrtplm.entity.*;
import cqrtplm.mapper.*;
import cqrtplm.service.DspfStatusModuleitemsubService;
import cqrtplm.service.RTChangeNoticeService;
import cqrtplm.service.RtCfgStatusInfoService;
import cqrtplm.vo.DspfStatusModultitemsubVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.assertj.core.util.Lists;
import org.flowable.engine.delegate.DelegateExecution;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class RTChangeNoticeServiceImpl implements RTChangeNoticeService {
    @Resource
    private TyplmPrincipalService typlmPrincipalService;
    @Resource
    private TyplmOrgService typlmOrgService;
    @Resource
    private TyplmPartService typlmPartService;
    @Resource
    private TyplmTypeService typlmTypeService;
    @Resource
    private TyplmBasedRuleService typlmBasedRuleService;
    @Resource
    private TyplmSegmentCodeService typlmSegmentCodeService;
    @Resource
    private TyplmWorkFlowService typlmWorkFlowService;
    @Resource
    private TyplmUserService typlmUserService;
    @Resource
    private TyplmWorkFlowContainerViewService typlmWorkFlowContainerViewService;
    @Resource
    private TyplmLogger typlmLogger;
    @Resource
    private TyplmEnumerationService typlmEnumerationService;
    @Resource
    private TyplmChangeObjectLinkService typlmChangeObjectLinkService;
    @Resource
    private TyplmChangeRequestService typlmChangeRequestService;
    @Resource
    private TyPlmWorkspaceObjectService tyPlmWorkSpaceObjectService;
    @Resource
    private TyplmWorkFlowProcessService typlmWorkFlowProcessService;
    @Resource
    private TyplmEcAgainstDataService typlmEcAgainstDataService;
    @Resource
    private TyplmWorkFlowContainerService typlmWorkFlowContainerService;
    @Resource
    private TyplmEngineeringChangeService typlmEngineeringChangeService;
    @Resource
    private TyplmFlowChangeRequestViewService typlmFlowChangeRequestViewService;
    @Resource
    private TyplmFormTemplateService typlmFormTemplateService;
    @Resource
    private TyplmChgNoticeQueryService typlmChgNoticeQueryService;
    @Resource
    private TyplmChangeLinkService typlmChangeLinkService;
    @Resource
    private TyplmFlowChgFormNoticeViewService typlmFlowChgFormNoticeViewService;
    @Resource
    private RtChangeaffectEbomMapper rtChangeaffectEbomMapper;
    @Resource
    private RtChangeaffectFinishedbomMapper rtChangeaffectFinishedbomMapper;
    @Resource
    private RtChangeaffectDrawingdocumentMapper rtChangeaffectDrawingdocumentMapper;
    @Resource
    private RtChangeaffectAssociatedbomMapper rtChangeaffectAssociatedbomMapper;
    @Resource
    private RtChangeaffectMbomMapper rtChangeaffectMbomMapper;
    @Resource
    private DspfStatusModuleitemsubService dspfStatusModuleitemsubService;
    @Resource
    private RTChangeMapper rtChangeMapper;
    @Resource
    private TyplmIterationService typlmIterationService;
    @Resource
    private TyChangeCheckService tyChangeCheckService;
    @Resource
    private TyChangeObjectLinkExtService changeObjectLinkExtService;
    @Resource
    private TyplmChgNoticeActivityLinkMapper typlmChgNoticeActivityLinkMapper;
    @Resource
    private TyplmFlowContainerObjectService typlmFlowContainerObjectService;
    @Resource
    private SnowflakeIdComponent snowflakeIdComponent;
    @Resource
    private TyplmChgNoticeActivityLinkService typlmChgNoticeActivityLinkService;
    @Resource
    private TyplmChgActRecordLinkService typlmChgActRecordLinkService;
    @Resource
    private TyplmChgActRelDataLinkService typlmChgActRelDataLinkService;
    @Resource
    private TyplmMpmWorkFlowAdaptationService tymMpmWorkFlowAdaptationService;
    @Resource
    private RtCfgStatusInfoService rtCfgStatusInfoService;
    @Resource
    private TyplmLifecycleTemplateService typlmLifecycleTemplateService;
    @Resource
    private TyplmCommonLifecycleService typlmCommonLifecycleService;
    @Resource
    private RtChangeaffectModuleMapper rtChangeaffectModuleMapper;
    @Resource
    private TyplmClassificationService typlmClassificationService;
    @Resource
    private RtCfgMzMapper rtCfgMzMapper;
    @Resource
    private RtZdMapper rtZdMapper;
    @Resource
    private RtChangeTargetDataMapper rtChangeTargetDataMapper;
    @Resource
    private TyplmDocumentService typlmDocumentService;
    @Resource
    private TyplmPdmPartService typlmPdmPartService;
    @Resource
    private TyplmPartRelObjectService typlmPartRelObjectService;
    @Resource
    private RtChangeLockInfoMapper rtChangeLockInfoMapper;
    @Resource
    private TyplmAttributeValueService typlmAttributeValueService;

    public StringBuffer errMsg;
    public List<String> errorList;
    @Resource
    private CommonService commonService;
    @Value("${sap.sourceList.username:test}")
    private String sapSourceListUsername;
    @Value("${sap.sourceList.password.:po654321}")
    private String sapSourceListPassword;
    @Value("${sap.sourceList.url:http://116.63.169.18:50000/RESTAdapter/qas/DSPF/SI_ZMM_DSPF2SAP_SOURCESLCT_SREQ}")
    private String sapSourceListUrl;

    /**
     * 根据ECN创建客户ECR
     *
     * @param workFlowContainerId
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createECR(String workFlowContainerId) throws Exception {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && workFlowContainerView instanceof FlowChgFormView) {
            log.info("当前流程属于变更通告流程");
            FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
            List<FlowTaskRecord> flowTaskRecordList = flowChgFormView.getFlowTaskRecordList();
            //获取变更通告对象
            ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
            ChgNoticeDO chgNoticeDO = this.typlmChgNoticeQueryService.selectByPrimaryKey(chgFormVO.getOid());
            if (Objects.isNull(chgNoticeDO)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_OBJECT_NOT_FOUND, new String[]{chgFormVO.getOid().toString()});
            }
            List<ChgRequestVO> list2 = typlmChangeLinkService.queryECRByECO(chgNoticeDO);
            if (CollUtil.isNotEmpty(list2)) {
                for (ChgRequestVO chgRequestVO : list2) {
                    String ecrNumber = chgRequestVO.getMasterNumber();
                    if (ecrNumber.contains("-")) {
                        //当前ECN已创建了大客户ECR
                        return;
                    }
                }
            }
            String ecnNumber = chgFormVO.getObjectNumber();
            if (ecnNumber.contains("-")) {
                //当前ECN是基于ECR创建的,不需要再次创建ECR
                return;
            }
            String issueName = chgFormVO.getName();
            BigInteger containerOid = chgFormVO.getContainerOid();
            String containerOtype = chgFormVO.getContainerOtype();
            String formData = chgFormVO.getFormData();
            boolean isBigCustomer = false;
            if (StringUtils.isNotBlank(formData)) {
                JSONObject formDataJson = JSONObject.parseObject(formData);
                JSONArray subform47946 = formDataJson.getJSONArray("subform47946");
                if (!ecnNumber.contains("RTTJST")) {
                    subform47946 = formDataJson.getJSONArray("subform57714");
                }
                if (CollectionUtils.isNotEmpty(subform47946)) {
                    //获取大客户枚举信息
                    Map<String, String> enmumap = this.typlmEnumerationService.getEnabledEnumItemsMap(Collections.singletonList("BigCustomer")).get("BigCustomer");
                    //获取表单大客户
                    for (int i = 0; i < subform47946.size(); i++) {
                        String customer = subform47946.getJSONObject(i).getString("input44037");
                        if (StringUtils.isNotBlank(customer)) {
                            //包含大客户
                            if (enmumap.containsKey(customer)) {
                                isBigCustomer = true;
                                break;
                            }
                        }
                    }
                }
            }
            //不包含大客户则不创建客户ECR
            if (!isBigCustomer) {
                return;
            }
            IdentifierEntity issueEntity = new IdentifierEntity(chgFormVO.getOid(), chgFormVO.getOtype());
            List<String> partNumberList = new ArrayList<>();
            List<ECObjData> ecobjList = chgFormVO.getEcObjDataVOS();
            if (CollectionUtils.isNotEmpty(ecobjList)) {
                for (ECObjData ecObjData : ecobjList) {
                    partNumberList.add(ecObjData.getObjectNumber());
                }
            }
            List<String> userNameList = new ArrayList<>();
            userNameList.add(chgFormVO.getCreatorName());
            //根据ECR的类型获取类型OID
            BigInteger typeOid = typlmTypeService.getTypeOidByName(RTPlmConstant.CUSTOMER_ECR);
            //获取ECR类型关联的初始化规则
            TyplmBaseRuleBoundedObjDTO typeBasedRuleEditDTO = this.typlmBasedRuleService.getBaseRuleBoundedObjInfo(typeOid, containerOid, containerOtype);
            //获取初始化规则中绑定的编码规则OID
            BigInteger ruleOid = typeBasedRuleEditDTO.getSegmentCodeOid();
            String ruleType = typeBasedRuleEditDTO.getSegmentCodeOtype();
            TyplmSegmentCodeConditionDTO param = new TyplmSegmentCodeConditionDTO();
            IdentifierEntity identifierEntity = new IdentifierEntity(ruleOid, ruleType);
            param.setRuleInfo(identifierEntity);
            param.setOtype(RTPlmConstant.ECR_TYPE);
            //根据编码规则创建ECR编码
            TyplmSegmentCodeRuleVO resultData = this.typlmSegmentCodeService.getSegmentFormData(param);
            String code = resultData.getCode();
            ObjNumberDTO objNumberDTO = new ObjNumberDTO();
            List list = new ArrayList();
            list.add(code);
            objNumberDTO.setObjNumberList(list);
            objNumberDTO.setObjOtype(RTPlmConstant.ECR_TYPE);
            //判断ECR编码是否已存在
            List<ObjNumberErrorVO> list1 = this.tyPlmWorkSpaceObjectService.judgeObjNumberIsExist(objNumberDTO.getObjNumberList(), objNumberDTO.getObjOtype());
            if (CollectionUtils.isNotEmpty(list1)) {
                return;
            }

            //组装创建ECR所需的基本信息
            TyplmChangeRequestDTO changeRequestDTO = new TyplmChangeRequestDTO();
            try {
                changeRequestDTO.setContaineroid(containerOid);
                changeRequestDTO.setContainerotype(containerOtype);
                changeRequestDTO.setTypeoid(typeOid);
                changeRequestDTO.setObjectNumber("RTTJZQ-" + ecnNumber);
                changeRequestDTO.setName(issueName);
                changeRequestDTO.setFileList(null);
                FormTemplateVO formTemplateVO = this.typlmFormTemplateService.getFormTemplateByType(typeOid);
                if (formTemplateVO != null) {
                    BigInteger oid = formTemplateVO.getOid();
                    String type = formTemplateVO.getOtype();
                    changeRequestDTO.setFormtemplateoid(oid);
                    changeRequestDTO.setFormtemplateotype(type);
                    changeRequestDTO.setFormData(formTemplateVO.getTemplatedata().toJSONString());
                }
                ChgRequestDetailVO changeRequest = this.typlmChangeRequestService.createChangeRequest(changeRequestDTO);
                //建立ECR与问题报告的关联
                IdentifierEntity mainObj = new IdentifierEntity(changeRequest.getOid(), changeRequest.getOtype());
                ArgumentUtils.checkArgumentNull(mainObj, "mainObj");
                List<IdentifierEntity> objectList = new ArrayList<>();
                IdentifierEntity entity = new IdentifierEntity(chgFormVO.getOid(), chgFormVO.getOtype());
                objectList.add(entity);
                ArgumentUtils.checkArgumentEmpty(objectList, "objectList");
                this.typlmChangeRequestService.createEcLinkObjByIdentifierEntity(mainObj, objectList);
                //将问题报告中受影响的对象添加到ECR中
                List<AffectedObjectDTO> affectobjectList = new ArrayList<>();
                if (!CollectionUtils.isEmpty(ecobjList)) {
                    for (ECObjData ecObjData : ecobjList) {
                        AffectedObjectDTO affectedObjectDTO = new AffectedObjectDTO(ecObjData.getOid(), ecObjData.getOtype(), ecObjData.getDescription());
                        affectobjectList.add(affectedObjectDTO);
                    }

                }
                if (!affectobjectList.isEmpty()) {
                    List<BigInteger> oidList = this.typlmEcAgainstDataService.batchCreateAffectedLinkList(mainObj, affectobjectList);
                    oidList.forEach((item) -> this.typlmLogger.info(new CTyEntityBaseDO(item, "ty.inteplm.change.CTyChangeAffectedLink"), LogEventEnum.CRATE_OBJECT));

                }
                //封装Oid oType 到 IdentifierEntity
                IdentifierEntity identifier = getIdentifierEntity(changeRequest);
                //查询变更请求详细信息
                FlowChangeRequestView flowChangeRequestView = this.typlmFlowChangeRequestViewService.getEmptyFlowChgFormView(identifier);
                //获取指定模板流程详细信息
                WorkFlow workFlow = getDefaultWorkFlow(RTPlmConstant.ECR_CHANGE_WORKFLOW);//
                //获取 List<PdmUserDTO> userList
                List<PdmUserDTO> userList = getPdmUserDTOS(userNameList);
                //查询流程模板每个流程节点的详细信息，并设置节点参与者
                List<UserTaskDTO> userTaskList = getUserTaskDTOS(workFlow, userList, containerOid, containerOtype);
                //获取 FlowChangeRequestView
                FlowChangeRequestView flowChangeRequestView1 = getFlowChangeRequestView(userTaskList, workFlow, flowChangeRequestView, userList);

                //启动流程
                this.typlmFlowChangeRequestViewService.insert(flowChangeRequestView1);
                this.typlmWorkFlowProcessService.startProcess(flowChangeRequestView1, true);
            } catch (Exception exception) {
                AuditLogDO auditLogDO = new AuditLogDO();
                auditLogDO.setObjoid(BigInteger.ZERO);
                auditLogDO.setObjotype(changeRequestDTO.getOtype());
                auditLogDO.setContaineroid(changeRequestDTO.getContaineroid());
                auditLogDO.setContainerotype(changeRequestDTO.getContainerotype());
                auditLogDO.setTargettype(changeRequestDTO.getTypeDefName());
                auditLogDO.setTargetname(changeRequestDTO.getName());
                auditLogDO.setTargetnumber(changeRequestDTO.getObjectNumber());
                auditLogDO.setTargetsecuritylabels(changeRequestDTO.getSecuritylabels());
                auditLogDO.setLifecyclestageotype(changeRequestDTO.getLifecyclestageotype());
                auditLogDO.setLifecyclestageoid(changeRequestDTO.getLifecyclestageoid());
                auditLogDO.setLifecyclestatekey(changeRequestDTO.getLifecyclestagekey());
                this.typlmLogger.errorInfo(LogEventEnum.CRATE_OBJECT, auditLogDO, exception);
                throw exception;
            }
        }
    }

    /**
     * 根据客户ECR创建ECN
     *
     * @param workFlowContainerId
     * @throws Exception
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createECN(String workFlowContainerId, String condition) throws Exception {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && workFlowContainerView instanceof FlowChangeRequestView) {
            log.info("当前流程属于变更请求流程");
            FlowChangeRequestView flowChangeRequestView = (FlowChangeRequestView) workFlowContainerView;
            List<FlowTaskRecord> flowTaskRecordList = flowChangeRequestView.getFlowTaskRecordList();
            //获取变更请求对象
            ChgRequestDetailVO chgRequestDetailVO = flowChangeRequestView.getChgRequestDetailVO();
            String ecrNumber = chgRequestDetailVO.getObjectNumber();
            if (ecrNumber.contains("-")) {
                //更改请求是根据设计变更创建,不需要创建ECN
                return;
            }
            //表单内容
            String formData = chgRequestDetailVO.getFormData();
            boolean isChange = false;
            String objectName = "";
            String displayObjectName = "";
            String noRule = "";
            String processName = "";
            if ("DESIGN_ECN".equals(condition)) {
                objectName = condition;
                displayObjectName = "设计变更通知单";
                noRule = "RTTJST";
                processName = RTPlmConstant.ECN_DESIGN_WORKFLOW;
            } else if ("ORDER_ECN".equals(condition)) {
                objectName = condition;
                displayObjectName = "订单更改通知单";
                noRule = "RTTJJG";
                processName = RTPlmConstant.ECN_ORDER_WORKFLOW;

            }
            //判断是否涉及大客户，并且销售确认变更
//            if (StringUtils.isNotBlank(formData)) {
//                JSONObject formDataJson = JSONObject.parseObject(formData);
//                JSONArray subform47946 = formDataJson.getJSONArray("subform44512");
//                if (CollectionUtils.isNotEmpty(subform47946)) {
//                    int count = 0;
//                    for (int i = 0; i < subform47946.size(); i++) {
//                        String saleConfirm = subform47946.getJSONObject(i).get("radio28579").toString();
//                        if (StringUtils.isBlank(saleConfirm))
//                            continue;
//                        if (saleConfirm.contains(","))
//                            saleConfirm = saleConfirm.split(",")[0];
//                        if ("是".equals(saleConfirm) || "1".equals(saleConfirm)) {
//                            count++;
//                        }
//                    }
//                    if (count != 0 && count == subform47946.size()) {
//                        isChange = true;
//                    }
//                }
//            }
//            if (isChange) {
            //销售确认后，创建涉及变更单
            String issueName = chgRequestDetailVO.getName();
            BigInteger containerOid = chgRequestDetailVO.getContaineroid();
            String containerOtype = chgRequestDetailVO.getContainerotype();
            IdentifierEntity issueEntity = new IdentifierEntity(chgRequestDetailVO.getOid(), chgRequestDetailVO.getOtype());
            List<String> partNumberList = new ArrayList<>();
            List<ECLinkObjDataCommonVO> eclinkObjList = this.typlmEcAgainstDataService.batchGetAffectedObjectListByOids(Collections.singletonList(chgRequestDetailVO.getOid()), chgRequestDetailVO.getOtype());
            if (CollectionUtils.isNotEmpty(eclinkObjList)) {
                for (ECLinkObjDataCommonVO ecLinkObjDataCommonVO : eclinkObjList) {
                    partNumberList.add(ecLinkObjDataCommonVO.getObjectNumber());
                }
            }
            List<String> userNameList = new ArrayList<>();
            userNameList.add(chgRequestDetailVO.getCreator());
            //根据ECR的类型获取类型OID
            BigInteger typeOid = typlmTypeService.getTypeOidByName(objectName);
            //获取ECR类型关联的初始化规则
            TyplmBaseRuleBoundedObjDTO typeBasedRuleEditDTO = this.typlmBasedRuleService.getBaseRuleBoundedObjInfo(typeOid, containerOid, containerOtype);
            //获取初始化规则中绑定的编码规则OID
            BigInteger ruleOid = typeBasedRuleEditDTO.getSegmentCodeOid();
            String ruleType = typeBasedRuleEditDTO.getSegmentCodeOtype();
            TyplmSegmentCodeConditionDTO param = new TyplmSegmentCodeConditionDTO();
            IdentifierEntity identifierEntity = new IdentifierEntity(ruleOid, ruleType);
            param.setRuleInfo(identifierEntity);
            param.setOtype(RTPlmConstant.ECN_TYPE);
            //根据编码规则创建ECN编码
            TyplmSegmentCodeRuleVO resultData = this.typlmSegmentCodeService.getSegmentFormData(param);
            String code = resultData.getCode();
            ObjNumberDTO objNumberDTO = new ObjNumberDTO();
            List list = new ArrayList();
            list.add(code);
            objNumberDTO.setObjNumberList(list);
            objNumberDTO.setObjOtype(RTPlmConstant.ECN_TYPE);
            //判断ECN编码是否已存在
            List<ObjNumberErrorVO> list1 = this.tyPlmWorkSpaceObjectService.judgeObjNumberIsExist(objNumberDTO.getObjNumberList(), objNumberDTO.getObjOtype());
            if (list1 == null || list1.size() == 0) {

            }
            LinkedHashMap<String, String> descriptionMap = new LinkedHashMap<>();
            ChgFormVO formVO = new ChgFormVO();
            formVO.setContainerOid(containerOid);
            formVO.setContainerOtype(containerOtype);
            formVO.setTypeOid(typeOid);
            formVO.setTypeDefName(displayObjectName);
            formVO.setObjectNumber(noRule + "-" + ecrNumber);
            formVO.setName(issueName);
            formVO.setFileList(new ArrayList<MultipartFile>());
            UserDO userDO = TyAccountContext.getUser();
            //            formVO.setCreatorOid(userDO.getOid());
            //            formVO.setCreatorOtype(userDO.getOtype());
            formVO.setCreatorName(userDO.getName());
            //            formVO.setOwnerOid(userDO.getOid());
            //            formVO.setOwnerOtype(userDO.getOtype());
            formVO.setOwnerName(userDO.getName());
            FormTemplateVO formTemplateVO = this.typlmFormTemplateService.getFormTemplateByType(typeOid);
            if (formTemplateVO != null) {
                BigInteger oid = formTemplateVO.getOid();
                String type = formTemplateVO.getOtype();
                formVO.setFormtemplateoid(oid);
                formVO.setFormtemplateotype(type);
                formVO.setFormData(formTemplateVO.getTemplatedata().toJSONString());
            }
            List<ECObjDTO> objectList = new ArrayList<>();
            if (CollectionUtils.isNotEmpty(eclinkObjList)) {
                for (ECLinkObjDataCommonVO ecLinkObjDataCommonVO : eclinkObjList) {
                    ECObjDTO ecObjDTO = new ECObjDTO();
                    ecObjDTO.setOid(ecLinkObjDataCommonVO.getOid());
                    ecObjDTO.setOtype(ecLinkObjDataCommonVO.getOtype());
                    ecObjDTO.setIdentifierRef(new IdentifierEntity(ecLinkObjDataCommonVO.getOid(), ecLinkObjDataCommonVO.getOtype()));
                    objectList.add(ecObjDTO);
                }
                formVO.setEcObjectList(objectList);
            }
            try {
                WorkFlow workFlow = getDefaultWorkFlow(processName);//
                //                formVO.setWorkFlowId(workFlow.getOid());
                ChgFormVO chgForm = this.typlmEngineeringChangeService.createChgFormNew(formVO, formVO.getFileList(), descriptionMap);
                TyplmAuditLogUtil.info(chgForm.getOid(), chgForm.getOtype(), LogEventEnum.CRATE_OBJECT);
                TyplmAuditLogUtil.sendCollectInfo();
                //建立ECR与ECN的关联
                IdentifierEntity mainObj = new IdentifierEntity(chgForm.getOid(), chgForm.getOtype());
                List<IdentifierEntity> ecrList = new ArrayList<>();
                IdentifierEntity entity = new IdentifierEntity(chgRequestDetailVO.getOid(), chgRequestDetailVO.getOtype());
                ecrList.add(entity);
                this.typlmChangeRequestService.createEcLinkObjByIdentifierEntity(mainObj, ecrList);
//                    FlowChgFormView containerView = this.typlmFlowChgFormNoticeViewService.getEmptyFlowChgFormView(mainObj);
                //封装Oid oType 到 IdentifierEntity
                FlowChgFormView containerView = new FlowChgFormView();
                containerView.setCodeNumber(code);
                containerView.setCode(code);
                containerView.setFormtemplateoid(formVO.getFormtemplateoid());
                containerView.setFormtemplateotype(formVO.getFormtemplateotype());
                containerView.setFormData(formVO.getFormData());
                containerView.setContainerOid(containerOid);
                containerView.setContainerOtype(containerOtype);
                containerView.setContainerName(chgForm.getContainerName());
                containerView.setWorkFlowId(workFlow.getOid());
                containerView.setWorkFlowName(workFlow.getName());
                containerView.setDeploymentId(workFlow.getDeploymentId());
                //获取 List<PdmUserDTO> userList
                List<PdmUserDTO> userList = getPdmUserDTOS(userNameList);
                //查询流程模板每个流程节点的详细信息，并设置节点参与者
                List<UserTaskDTO> userTaskList = getUserTaskDTOS(workFlow, userList, containerOid, containerOtype);
                containerView.setUserTaskList(userTaskList);
                containerView.setBaseObjectOid(chgForm.getOid());
                containerView.setBaseObjectOtype(chgForm.getOtype());
                containerView.setEmergencyDegree("commonly");
                containerView.setWorkFlowOtype(workFlow.getOtype());
                containerView.setName(chgForm.getObjectNumber() + "," + chgForm.getName() + "_变更审批流程");
                containerView.setCreatorOid(formVO.getCreatorOid());
                containerView.setCreatorOtype(formVO.getCreatorOtype());
                containerView.setChgFormVO(chgForm);
                List<PdmUserDTO> pdmUserDTOList = getPdmUserDTOS(userNameList);
                //查询流程模板每个流程节点的详细信息，并设置节点参与者
                //                List<UserTaskDTO> userTaskDTOList = getUserTaskDTOS(workFlow, pdmUserDTOList, containerOid, containerOtype);
                containerView.setManagerList(pdmUserDTOList);
                this.typlmFlowChgFormNoticeViewService.insert(containerView);
                this.typlmWorkFlowProcessService.startProcess(containerView, true);
                TyplmAuditLogUtil.info(containerView.getOid(), containerView.getOtype(), LogEventEnum.ENABLE);
                //启动流程

            } catch (Exception exception) {
                AuditLogDO auditLogDO = new AuditLogDO();
                auditLogDO.setObjoid(BigInteger.ZERO);
                auditLogDO.setObjotype(formVO.getEcnOtype());
                auditLogDO.setContaineroid(formVO.getContainerOid());
                auditLogDO.setContainerotype(formVO.getContainerOtype());
                auditLogDO.setTargettype(formVO.getType());
                auditLogDO.setTargetnumber(formVO.getName());
                auditLogDO.setTargetsecuritylabels(formVO.getSecuritylabels());
                auditLogDO.setLifecyclestageoid(formVO.getLifecycleTemplateOid());
                auditLogDO.setLifecyclestageotype(formVO.getLifecycleTemplateOtype());
                auditLogDO.setLifecyclestatekey(formVO.getLifecycleStageKey());
                TyplmAuditLogUtil.errorInfo(LogEventEnum.CRATE_OBJECT, auditLogDO, exception);
                throw exception;
            }
        }
//        }
    }

    /**
     * 收集变更对象到变更前和变更后对象中
     *
     * @param workFlowContainerId
     * @throws Exception
     */
    @Transactional
    @Override
    public void collectChangeObjects(String workFlowContainerId) {
        try {
            WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
            if (!Objects.isNull(workFlowContainerView) && (workFlowContainerView instanceof FlowChgFormView || workFlowContainerView instanceof FlowChangeRequestView)) {
                log.info("当前流程属于变更通告流程");
                //表单内容
                String formData = "";
                TyAccountContext.setIgnoreAuth(true);
                if (workFlowContainerView instanceof FlowChangeRequestView) {
                    FlowChangeRequestView flowChangeRequestView = (FlowChangeRequestView) workFlowContainerView;
                    //获取变更请求对象
                    ChgRequestDetailVO chgRequestDetailVO = flowChangeRequestView.getChgRequestDetailVO();
                    List<ECLinkObjDataCommonVO> eclinkObjList = this.typlmEcAgainstDataService.batchGetAffectedObjectListByOids(Collections.singletonList(chgRequestDetailVO.getOid()), chgRequestDetailVO.getOtype());
                    String changeNo = chgRequestDetailVO.getObjectNumber();
                    List<IdentifierEntity> list = flowChangeRequestView.getReferenceList();
                    if (CollectionUtils.isNotEmpty(eclinkObjList)) {

                    }
                    //受影响的EBOM
                    List<RtChangeaffectEbomDO> rtChangeaffectEbomDOS = this.rtChangeaffectEbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                    //受影响的成品BOM
                    List<RtChangeaffectFinishedbomDO> rtChangeaffectFinishedbomDOS = this.rtChangeaffectFinishedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                    //关联受影响的BOM
                    List<RtChangeaffectAssociatedbomDO> rtChangeaffectAssociatedbomDOS = this.rtChangeaffectAssociatedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                    //受影响的图纸
                    List<RtChangeaffectDrawingdocumentDO> rtChangeaffectDrawingdocumentDOS = this.rtChangeaffectDrawingdocumentMapper.queryByChangeNoAndPartNo(changeNo, "");
                    //变更前对象
                    List<ECObjDTO> entityList = new ArrayList<>();
                    for (RtChangeaffectDrawingdocumentDO drawingdocumentDO : rtChangeaffectDrawingdocumentDOS) {
                        String id = drawingdocumentDO.getObjectid();
                        String type = drawingdocumentDO.getObjecttype();
                        String number = drawingdocumentDO.getDocumentnumber();
                        //收集变更前对象
                        buildEcABeforeVOListByOid(id, type, entityList);
                    }
                    for (RtChangeaffectEbomDO changeaffectEbomDO : rtChangeaffectEbomDOS) {
                        String id = changeaffectEbomDO.getObjectid();
                        String type = changeaffectEbomDO.getObjecttype();
                        //收集变更前对象
                        buildEcABeforeVOListByOid(id, type, entityList);
                    }

                    for (RtChangeaffectFinishedbomDO finishedbomDO : rtChangeaffectFinishedbomDOS) {
                        String id = finishedbomDO.getObjectid();
                        String type = finishedbomDO.getObjecttype();
                        //收集变更前对象
                        buildEcABeforeVOListByOid(id, type, entityList);
                    }
                    for (RtChangeaffectAssociatedbomDO associatedbomDO : rtChangeaffectAssociatedbomDOS) {
                        String id = associatedbomDO.getObjectid();
                        String type = associatedbomDO.getObjecttype();
                        //收集变更前对象
                        buildEcABeforeVOListByOid(id, type, entityList);
                    }
                    List<String> msgList = new ArrayList<>();
                    formData = chgRequestDetailVO.getFormData();
                    if (StringUtils.isNotBlank(formData)) {
                        JSONObject formDataJson = JSONObject.parseObject(formData);
                        JSONArray subform44512 = formDataJson.getJSONArray("subform47946");
                        if (CollectionUtils.isNotEmpty(subform44512)) {
                            for (int i = 0; i < subform44512.size(); i++) {
                                String beforeChangeNo = subform44512.getJSONObject(i).getString("input91754");
                                if (StringUtils.isNotBlank(beforeChangeNo)) {
                                    PartDO partDO = typlmPdmPartService.queryLastPartDoByPartNumber(beforeChangeNo);
                                    if (partDO != null) {
                                        String partNumber = partDO.getPartnumber();
                                        IdentifierEntity entity = new IdentifierEntity();
                                        entity.setOid(partDO.getOid());
                                        entity.setOtype(partDO.getOtype());
                                        List<ChgRequestDetailVO> ecrList = this.typlmChangeRequestService.getChangeRequestListByIdentifierEntity(entity);
                                        for (ChgRequestDetailVO ecr : ecrList) {
                                            String lifecyclestagekey = ecr.getLifecyclestagekey();
                                            String objectNumber = ecr.getObjectNumber();
                                            if ("IMPLEMENTATION".equals(lifecyclestagekey) || "UNDERREVIEW".equals(lifecyclestagekey)) {
                                                msgList.add(partNumber + "已在“" + objectNumber + "”ECR流程中");
                                            }
                                        }
                                    }
                                    //收集变更前对象
                                    buildEcABeforeVOListByNumber(beforeChangeNo, entityList, "", RTPlmConstant.VIEW_DESIGN);
                                }
                            }
                        }
                    }
                    if (CollUtil.isNotEmpty(msgList)) {
                        throw RTErrorCodeEnum.CUSTOM_EXCEPTION.getException("提示：" + String.join(",", msgList) + "，请勿重复创建！");
                    }
                    List<String> collect = this.typlmEcAgainstDataService.batchGetAffectedObjectListByOids(Collections.singletonList(workFlowContainerView.getBaseObjectOid()), "ty.inteplm.change.CTyChangeRequest").stream().map(e -> e.getLinkoid().toString()).collect(Collectors.toList());
                    typlmEcAgainstDataService.batchDeleteAffectedLinkList(collect);
                    //批量添加受影响的对象
                    List<AffectedObjectDTO> affectobjectList = new ArrayList<>();
                    if (!CollectionUtils.isEmpty(entityList)) {
                        for (ECObjDTO ecObjDTO : entityList) {
                            AffectedObjectDTO affectedObjectDTO = new AffectedObjectDTO(ecObjDTO.getOid(), ecObjDTO.getOtype(), ecObjDTO.getDescription());
                            affectobjectList.add(affectedObjectDTO);
                        }
                    }

                    if (!affectobjectList.isEmpty()) {
                        IdentifierEntity mainObj = new IdentifierEntity(chgRequestDetailVO.getOid(), chgRequestDetailVO.getOtype());
                        List<BigInteger> oidList = this.typlmEcAgainstDataService.batchCreateAffectedLinkList(mainObj, affectobjectList);
                    }
                } else if (workFlowContainerView instanceof FlowChgFormView) {
                    FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                    //获取变更通告对象
                    ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
                    List<ChgActivityDO> chgActivityDOList = this.typlmChgNoticeActivityLinkService.queryECAByECNId(chgFormVO.getOid());
                    List<ChgActRecordLinkDO> chgActRecordLinkDOList = new ArrayList<>();
                    ChgActivityDO chgActivityDO = null;
                    if (chgActivityDOList != null && chgActivityDOList.size() > 0) {
                        chgActivityDO = chgActivityDOList.get(0);
                    }
                    formData = chgFormVO.getFormData();
                    List<ECObjData> list = chgFormVO.getEcObjDataVOS();
                    String changeNo = chgFormVO.getObjectNumber();
                    List<ECObjDTO> entityList = new ArrayList<>();
                    if (changeNo.contains("RTTJXM")) {
                        if (StringUtils.isNotBlank(formData)) {
                            JSONObject formDataJson = JSONObject.parseObject(formData);
                            JSONArray subform47946 = formDataJson.getJSONArray("subform47946");
                            if (CollectionUtils.isNotEmpty(subform47946)) {
                                //图纸更改
                                for (int i = 0; i < subform47946.size(); i++) {
                                    String afterChangeNo = subform47946.getJSONObject(i).getString("radio73127");
                                    if (StringUtils.isNotBlank(afterChangeNo) && afterChangeNo.contains(",")) {
                                        afterChangeNo = afterChangeNo.split(",")[0];
                                    }
                                    //收集变更后对象
                                    buildEcAffectVOList(chgActivityDO, afterChangeNo, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);
                                }
                            }
                        }
                    } else {
                        //受影响的EBOM
                        List<RtChangeaffectEbomDO> rtChangeaffectEbomDOS = this.rtChangeaffectEbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                        //受影响的成品BOM
                        List<RtChangeaffectFinishedbomDO> rtChangeaffectFinishedbomDOS = this.rtChangeaffectFinishedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                        //关联受影响的BOM
                        List<RtChangeaffectAssociatedbomDO> rtChangeaffectAssociatedbomDOS = this.rtChangeaffectAssociatedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                        //受影响的图纸
                        List<RtChangeaffectDrawingdocumentDO> rtChangeaffectDrawingdocumentDOS = this.rtChangeaffectDrawingdocumentMapper.queryByChangeNoAndPartNo(changeNo, "");
                        //变更前对象
                        if (StringUtils.isNotBlank(formData)) {
                            JSONObject formDataJson = JSONObject.parseObject(formData);
                            JSONArray subform47946 = formDataJson.getJSONArray("subform47946");
                            JSONArray subform57714 = formDataJson.getJSONArray("subform57714");
                            if (CollectionUtils.isNotEmpty(subform47946)) {
                                //图纸更改
                                for (int i = 0; i < subform47946.size(); i++) {
                                    String type = subform47946.getJSONObject(i).get("radio81926").toString();
                                    String beforeChangeNo = subform47946.getJSONObject(i).getString("input67563");
                                    String afterChangeNo = subform47946.getJSONObject(i).getString("radio73127");
                                    String beforeVer = subform47946.getJSONObject(i).getString("input83973");
                                    if (StringUtils.isNotBlank(afterChangeNo) && afterChangeNo.contains(",")) {
                                        afterChangeNo = afterChangeNo.split(",")[0];
                                    }
                                    if ("图号升级".equals(type)) {
                                        List<RtChangeaffectDrawingdocumentDO> drawDOS = rtChangeaffectDrawingdocumentDOS.stream().filter(item -> item.getPartnumber().equals(beforeChangeNo)).collect(Collectors.toList());
                                        List<RtChangeaffectEbomDO> ebomDOS = rtChangeaffectEbomDOS.stream().filter(item -> item.getPartnumber().equals(beforeChangeNo)).collect(Collectors.toList());
                                        List<RtChangeaffectFinishedbomDO> finishedbomDOS = rtChangeaffectFinishedbomDOS.stream().filter(item -> item.getPartnumber().equals(beforeChangeNo)).collect(Collectors.toList());
                                        for (RtChangeaffectDrawingdocumentDO drawingdocumentDO : drawDOS) {
                                            String id = drawingdocumentDO.getObjectid();
                                            String objecttype = drawingdocumentDO.getObjecttype();
                                            String relatetype = drawingdocumentDO.getRelatetype();
                                            if ("EBOM号".equals(relatetype) || relatetype.contains("父物料") || relatetype.contains("初始选定的")) {
                                                //收集变更前对象
                                                buildEcABeforeVOListByOid(id, objecttype, entityList);
                                            }
                                        }
                                        for (RtChangeaffectEbomDO changeaffectEbomDO : ebomDOS) {
                                            String id = changeaffectEbomDO.getObjectid();
                                            String objecttype = changeaffectEbomDO.getObjecttype();
                                            //收集变更前对象
                                            buildEcABeforeVOListByOid(id, objecttype, entityList);
                                        }
                                        for (RtChangeaffectFinishedbomDO finishedbomDO : finishedbomDOS) {
                                            String id = finishedbomDO.getObjectid();
                                            String objecttype = finishedbomDO.getObjecttype();
                                            //收集变更前对象
                                            buildEcABeforeVOListByOid(id, objecttype, entityList);
                                        }
                                        //收集变更前对象-图样代号
                                        buildEcABeforeVOListByNumber(beforeChangeNo, entityList, type, RTPlmConstant.VIEW_DESIGN);
                                        //收集变更前对象-衍生物料码
//                                        List<JSONObject> materialList = rtChangeMapper.queryMaterialCode(beforeChangeNo,RTPlmConstant.MATERIALCODE, RTPlmConstant.PRODUCTTYPE);
//                                        if (CollUtil.isNotEmpty(materialList)){
//                                            for (JSONObject materJson : materialList) {
//                                                String materialCode = materJson.getString("PARTNUMBER");
//                                                buildEcABeforeVOListByNumber(materialCode, entityList, type, RTPlmConstant.VIEW_DESIGN);
//                                            }
//                                        }
                                        //收集变更后对象-图样代号
                                        buildEcAffectVOList(chgActivityDO, afterChangeNo, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);
                                        //收集变更后对象-衍生物料码
//                                        materialList = rtChangeMapper.queryMaterialCode(afterChangeNo,RTPlmConstant.MATERIALCODE, RTPlmConstant.PRODUCTTYPE);
//                                        if (CollUtil.isNotEmpty(materialList)){
//                                            for (JSONObject materJson : materialList) {
//                                                String materialCode = materJson.getString("PARTNUMBER");
//                                                buildEcAffectVOList(chgActivityDO, materialCode, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);
//                                            }
//                                        }
                                        for (RtChangeaffectFinishedbomDO finishedbomDO : finishedbomDOS) {
                                            String partNumber = finishedbomDO.getPartnumber();
                                            if (partNumber.equals(beforeChangeNo)) {
                                                String beforeMaterialcode = finishedbomDO.getMaterialcode();
                                                String colorCode = "";
                                                if ("H".equals(beforeMaterialcode.charAt(5))) {
                                                    colorCode = beforeMaterialcode.split("-")[1];
                                                } else {
                                                    colorCode = beforeMaterialcode.split("-")[2];
                                                }
                                                if (StringUtils.isNotBlank(beforeMaterialcode)) {
                                                    String afterMaterialcode = afterChangeNo + "-" + colorCode;
                                                    //收集变更前对象
                                                    buildEcABeforeVOListByNumber(beforeMaterialcode, entityList, type, RTPlmConstant.VIEW_DESIGN);
                                                    //收集变更后对象
                                                    buildEcAffectVOList(chgActivityDO, afterMaterialcode, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);
                                                }
                                            }
                                        }
                                    } else if ("图纸升版".equals(type)) {
                                        List<RtChangeaffectDrawingdocumentDO> drawDOS = rtChangeaffectDrawingdocumentDOS.stream().filter(item -> item.getPartnumber().equals(beforeChangeNo)).collect(Collectors.toList());
                                        for (RtChangeaffectDrawingdocumentDO drawingdocumentDO : drawDOS) {
                                            String id = drawingdocumentDO.getObjectid();
                                            String objecttype = drawingdocumentDO.getObjecttype();
                                            String relatetype = drawingdocumentDO.getRelatetype();
                                            //收集变更前对象图文档对象
//                                            buildEcABeforeVOListByOid(id, objecttype, entityList);
                                            if ("初始选定的".equals(relatetype)) {
                                                buildEcAffectVODrawList(chgActivityDO, id, objecttype, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);
                                            }
                                        }
                                        //取消收集图样代号的零部件对象
                                        buildEcAffectVOList(chgActivityDO, beforeChangeNo, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);

                                    }
                                }
                            }
                            if (CollectionUtils.isNotEmpty(subform57714)) {
                                for (int i = 0; i < subform57714.size(); i++) {
                                    String type = subform57714.getJSONObject(i).get("input70284").toString();
                                    String beforeChangeNo = subform57714.getJSONObject(i).getString("input36063");
                                    String afterChangeNo = subform57714.getJSONObject(i).getString("input37516");
                                    List<RtChangeaffectAssociatedbomDO> associatedbomDOS = null;
                                    if (type.equals("修改") || type.equals("删除")) {
                                        associatedbomDOS = rtChangeaffectAssociatedbomDOS.stream().filter(item -> item.getPartnumber().equals(beforeChangeNo)).collect(Collectors.toList());
                                    } else if ("增加".equals(type)) {
                                        associatedbomDOS = rtChangeaffectAssociatedbomDOS.stream().filter(item -> item.getPartnumber().equals(afterChangeNo)).collect(Collectors.toList());
                                    }
                                    for (RtChangeaffectAssociatedbomDO associatedbomDO : associatedbomDOS) {
                                        String id = associatedbomDO.getObjectid();
                                        String objecttype = associatedbomDO.getObjecttype();
                                        //收集变更前对象
                                        buildEcABeforeVOListByOid(id, objecttype, entityList);
                                        String bomType = associatedbomDO.getBomtype();
                                        String code = associatedbomDO.getCode();
                                        if ("EBOM号".equals(bomType)) {
                                            List<DocDetails> docDetails = this.typlmPartRelObjectService.queryPartRelatedDocInfo(new BigInteger(id));
                                            if (docDetails != null) {
                                                for (DocDetails docDetail : docDetails) {
                                                    buildEcABeforeVOListByOid(docDetail.getOid(), docDetail.getOtype(), entityList);
                                                }
                                            }
                                        }
                                        //收集变更前对象-EBOM号、成品码
                                        buildEcABeforeVOListByNumber(code, entityList, type, RTPlmConstant.VIEW_DESIGN);

                                    }
                                    if (type.equals("增加")) {
                                        buildEcAffectVOList(chgActivityDO, afterChangeNo, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);
                                    } else if (type.equals("修改") || type.equals("替换")) {
                                        //收集变更前对象
                                        buildEcABeforeVOListByNumber(beforeChangeNo, entityList, type, RTPlmConstant.VIEW_DESIGN);
                                        //收集变更后对象
                                        buildEcAffectVOList(chgActivityDO, afterChangeNo, chgActRecordLinkDOList, RTPlmConstant.VIEW_DESIGN);

                                    }
                                }
                            }
                        }
                    }
                    //根据oid和otype去重
                    List<ECObjDTO> distEntityList = entityList.stream().collect(Collectors.collectingAndThen(Collectors.toMap(e -> Arrays.asList(e.getOid(), e.getOtype()), e -> e, (existing, replacement) -> existing), map -> new ArrayList<>(map.values())));
                    List<ChgActRecordLinkDO> distLinkList = chgActRecordLinkDOList.stream().collect(Collectors.collectingAndThen(Collectors.toMap(e -> Arrays.asList(e.getOid(), e.getOtype()), e -> e, (existing, replacement) -> existing), map -> new ArrayList<>(map.values())));

                    //查询变更对象
                    ChgFormVO vo = this.typlmEngineeringChangeService.getChgFormByEcIdentifierEntity(new IdentifierEntity(flowChgFormView.getBaseObjectOid(), "ty.inteplm.change.CTyChangeNotice"), new TyplmFlowTaskInfoDTO());
                    List<ECObjData> beforeList = vo.getEcObjDataVOS();
                    List<ECObjData> afterList = vo.getEcAffectVOS();
                    if (CollectionUtils.isEmpty(beforeList)) {
                        //添加变更前对象
                        if (CollUtil.isNotEmpty(distEntityList)) {
                            ECAddChangeObjectDTO ecAddChangeObjectDTO = new ECAddChangeObjectDTO();
                            ecAddChangeObjectDTO.setEntityList(distEntityList);
                            ecAddChangeObjectDTO.setBefore(true);
                            ecAddChangeObjectDTO.setSaveDataBase(false);
                            ecAddChangeObjectDTO.setEntity(new IdentifierEntity(flowChgFormView.getBaseObjectOid(), "ty.inteplm.change.CTyChangeNotice"));
                            this.typlmEngineeringChangeService.addBeforeChangeObjectWithStrategy(ecAddChangeObjectDTO);
                        }
                    } else {

                        //根据oid和otype组装Set集合用于判重
                        Set<String> beforeCombinedKeys = beforeList.stream().map(ecObjData -> ecObjData.getOid() + "|" + ecObjData.getOtype()).collect(Collectors.toSet());
                        Set<String> entityCombinedKeys = distEntityList.stream().map(ecObjDTO -> ecObjDTO.getOid() + "|" + ecObjDTO.getOtype()).collect(Collectors.toSet());
                        //获取变更对象列表不包含表单中的变更对象数据
                        List<ECObjData> newBeforeList = beforeList.stream().filter(ecObjData -> !entityCombinedKeys.contains(ecObjData.getOid() + "|" + ecObjData.getOtype())).collect(Collectors.toList());
                        //获取变表单中变更不包含已添加到变更对象中的数据
                        List<ECObjDTO> newEntityList = distEntityList.stream().filter(ecObjDTO -> !beforeCombinedKeys.contains(ecObjDTO.getOid() + "|" + ecObjDTO.getOtype())).collect(Collectors.toList());
                        //删除变更对象
                        if (CollUtil.isNotEmpty(newBeforeList)) {
                            List<IdentifierEntity> l2 = newBeforeList.stream().map(v -> new IdentifierEntity(v.getOid(), v.getOtype())).collect(Collectors.toList());
                            this.typlmEngineeringChangeService.removeObjectBeforeChange(new IdentifierEntity(workFlowContainerView.getBaseObjectOid(), "ty.inteplm.change.CTyChangeNotice"), l2);
                        }
                        //添加变更前对象
                        if (CollUtil.isNotEmpty(newEntityList)) {
                            ECAddChangeObjectDTO ecAddChangeObjectDTO = new ECAddChangeObjectDTO();
                            ecAddChangeObjectDTO.setEntityList(newEntityList);
                            ecAddChangeObjectDTO.setBefore(true);
                            ecAddChangeObjectDTO.setSaveDataBase(false);
                            ecAddChangeObjectDTO.setEntity(new IdentifierEntity(flowChgFormView.getBaseObjectOid(), "ty.inteplm.change.CTyChangeNotice"));
                            this.typlmEngineeringChangeService.addBeforeChangeObjectWithStrategy(ecAddChangeObjectDTO);
                        }
                    }
                    if (CollectionUtils.isEmpty(afterList)) {
                        //添加变更后对象
                        if (CollUtil.isNotEmpty(distLinkList)) {
                            this.typlmChgActRecordLinkService.batchInsertSelective(distLinkList);
                        }
                    } else {
                        //根据oid和otype组装Set集合用于判重
                        Set<String> afterCombinedKeys = afterList.stream().map(ecObjData -> ecObjData.getOid() + "|" + ecObjData.getOtype()).collect(Collectors.toSet());
                        Set<String> recordCombinedKeys = distLinkList.stream().map(recordLinkDO -> recordLinkDO.getOid() + "|" + recordLinkDO.getOtype()).collect(Collectors.toSet());
                        //获取变更对象列表不包含表单中的变更对象数据
                        List<ECObjData> newAfterList = afterList.stream().filter(ecObjData -> !recordCombinedKeys.contains(ecObjData.getOid() + "|" + ecObjData.getOtype())).collect(Collectors.toList());
                        //获取变表单中变更不包含已添加到变更对象中的数据
                        List<ChgActRecordLinkDO> newRecordList = distLinkList.stream().filter(recordLinkDO -> !afterCombinedKeys.contains(recordLinkDO.getOid() + "|" + recordLinkDO.getOtype())).collect(Collectors.toList());

                        //删除变更后对象
                        if (CollUtil.isNotEmpty(newAfterList)) {
                            List<ECObjDataVO> vos = BeanUtil.copyToList(newAfterList, ECObjDataVO.class);
                            this.typlmEngineeringChangeService.removeObjectAfterChange(new IdentifierEntity(workFlowContainerView.getBaseObjectOid(), "ty.inteplm.change.CTyChangeNotice"), vos, vos);
                        }
                        //添加变更后对象
                        if (CollUtil.isNotEmpty(newRecordList)) {
                            this.typlmChgActRecordLinkService.batchInsertSelective(newRecordList);
                        }
                    }
                }
                TyAccountContext.setIgnoreAuth(false);
            }
        } catch (Exception e) {
            throw RTErrorCodeEnum.COLLECTION_OBJECT_ERROR.getException(e.getMessage());
        }
    }

    /**
     * @param workFlowContainerId
     * @throws Exception
     */
    @Transactional
    @Override
    public void collectChangeMboms(String workFlowContainerId) throws Exception {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && (workFlowContainerView instanceof FlowChgFormView || workFlowContainerView instanceof FlowChangeRequestView)) {
            log.info("当前流程属于变更通告流程");
            //表单内容
            String formData = "";
            if (workFlowContainerView instanceof FlowChgFormView) {
                FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                //获取变更通告对象
                ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
                List<ChgActivityDO> chgActivityDOList = this.typlmChgNoticeActivityLinkService.queryECAByECNId(chgFormVO.getOid());
                List<ChgActRecordLinkDO> chgActRecordLinkDOList = new ArrayList<>();
                ChgActivityDO chgActivityDO = null;
                if (CollectionUtils.isNotEmpty(chgActivityDOList)) {
                    for (ChgActivityDO chgActivityDO1 : chgActivityDOList) {
                        String type = chgActivityDO1.getDescription();
                        if ("零部件".equals(type) || StringUtils.isBlank(type)) {
                            chgActivityDO = chgActivityDO1;
                        }
                    }
                }
                formData = chgFormVO.getFormData();
                List<ECObjData> list = chgFormVO.getEcObjDataVOS();
                String changeNo = chgFormVO.getObjectNumber();
                //受影响的MBOM
                List<RtChangeaffectMbomDO> rtChangeaffectMbomDOS = this.rtChangeaffectMbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                //变更前对象
                List<ECObjDTO> entityList = new ArrayList<>();
                for (RtChangeaffectMbomDO mbomDO : rtChangeaffectMbomDOS) {
                    String mbomNum = mbomDO.getMbom();
                    String factory = mbomDO.getFactory();
                    JSONObject jsonObject = this.rtChangeMapper.queryLatestMaterialByCode(mbomNum, factory);
                    if (jsonObject != null) {
                        String id = jsonObject.getString("OID");
                        String type = jsonObject.getString("OTYPE");
                        //收集变更前对象
                        buildEcABeforeVOListByOid(id, type, entityList);
                    }
                }
                if (StringUtils.isNotBlank(formData)) {
                    JSONObject formDataJson = JSONObject.parseObject(formData);
                    JSONArray subform47946 = formDataJson.getJSONArray("subform47946");
                    JSONArray subform57714 = formDataJson.getJSONArray("subform57714");
                    if (CollectionUtils.isNotEmpty(subform47946)) {
                        //图纸更改
                        for (int i = 0; i < subform47946.size(); i++) {
                            String type = subform47946.getJSONObject(i).get("radio81926").toString();
                            String beforeChangeNo = subform47946.getJSONObject(i).getString("input67563");
                            String afterChangeNo = subform47946.getJSONObject(i).getString("radio73127");
                            if (StringUtils.isNotBlank(afterChangeNo) && afterChangeNo.contains(",")) {
                                afterChangeNo = afterChangeNo.split(",")[0];
                            }
                            if ("图号升级".equals(type)) {
                                for (RtChangeaffectMbomDO mbomDO : rtChangeaffectMbomDOS) {
                                    String partNumber = mbomDO.getPartnumber();
                                    String factory = mbomDO.getFactory();
                                    String parttype = mbomDO.getParttype();
                                    if ("PatternCode".equals(parttype)) {
                                        if (partNumber.equals(beforeChangeNo)) {
                                            String beforeMaterialcode = mbomDO.getMaterialcode();
                                            String colorCode = "";
                                            if ("H".equals(beforeMaterialcode.charAt(5))) {
                                                colorCode = beforeMaterialcode.split("-")[1];
                                            } else {
                                                colorCode = beforeMaterialcode.split("-")[2];
                                            }
                                            if (StringUtils.isNotBlank(beforeMaterialcode)) {
                                                String afterMaterialcode = afterChangeNo + "-" + colorCode;
                                                //收集变更前对象
                                                buildEcABeforeVOListByNumber(beforeMaterialcode, entityList, type, factory);
                                                //收集变更后对象
                                                buildEcAffectVOList(chgActivityDO, afterMaterialcode, chgActRecordLinkDOList, factory);
                                            }
                                        }
                                    } else {
                                        if (partNumber.equals(beforeChangeNo)) {
                                            //收集变更前对象
                                            buildEcABeforeVOListByNumber(beforeChangeNo, entityList, type, factory);
                                            //收集变更后对象
                                            buildEcAffectVOList(chgActivityDO, afterChangeNo, chgActRecordLinkDOList, factory);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (CollectionUtils.isNotEmpty(subform57714)) {
                        //关联变更件替换说明
                        for (int i = 0; i < subform57714.size(); i++) {
                            String type = subform57714.getJSONObject(i).get("input70284").toString();
                            String beforeChangeNo = subform57714.getJSONObject(i).getString("input36063");
                            String afterChangeNo = subform57714.getJSONObject(i).getString("input37516");
                            if (type.equals("增加")) {
                                for (RtChangeaffectMbomDO mbomDO : rtChangeaffectMbomDOS) {
                                    String partNumber = mbomDO.getPartnumber();
                                    String factory = mbomDO.getFactory();
                                    if (partNumber.equals(afterChangeNo)) {
                                        String afterMaterialcode = mbomDO.getMaterialcode();
                                        //收集变更后对象
                                        buildEcAffectVOList(chgActivityDO, afterMaterialcode, chgActRecordLinkDOList, factory);
                                    }
                                }
                            } else if (type.equals("删除") || type.equals("移动")) {
//                                for (RtChangeaffectMbomDO mbomDO : rtChangeaffectMbomDOS) {
//                                    String partNumber = mbomDO.getPartnumber();
//                                    String factory = mbomDO.getFactory();
//                                    if (partNumber.equals(beforeChangeNo)) {
//                                        String beforeMaterialcode = mbomDO.getMaterialcode();
//                                        buildEcABeforeVOListByNumber(beforeMaterialcode, entityList, type, factory);
//                                    }
//                                }
                            } else if (type.equals("修改") || type.equals("替换")) {
                                for (RtChangeaffectMbomDO mbomDO : rtChangeaffectMbomDOS) {
                                    String partNumber = mbomDO.getPartnumber();
                                    String factory = mbomDO.getFactory();
                                    String parttype = mbomDO.getParttype();
                                    if ("PatternCode".equals(parttype)) {
                                        if (partNumber.equals(beforeChangeNo)) {
                                            String beforeMaterialcode = mbomDO.getMaterialcode();
                                            String colorCode = "";
                                            if ("H".equals(beforeMaterialcode.charAt(5))) {
                                                colorCode = beforeMaterialcode.split("-")[1];
                                            } else {
                                                colorCode = beforeMaterialcode.split("-")[2];
                                            }
                                            if (StringUtils.isNotBlank(beforeMaterialcode)) {
                                                String afterMaterialcode = afterChangeNo + "-" + colorCode;
                                                //收集变更前对象
                                                buildEcABeforeVOListByNumber(beforeMaterialcode, entityList, type, factory);
                                                //收集变更后对象
                                                buildEcAffectVOList(chgActivityDO, afterMaterialcode, chgActRecordLinkDOList, factory);
                                            }
                                        }
                                    } else {
                                        //收集变更前对象
                                        buildEcABeforeVOListByNumber(beforeChangeNo, entityList, type, factory);
                                        //收集变更后对象
                                        buildEcAffectVOList(chgActivityDO, afterChangeNo, chgActRecordLinkDOList, factory);
                                    }
                                }
                            }
                        }
                    }
                    //根据oid和otype去重
                    List<ECObjDTO> distEntityList = entityList.stream().collect(Collectors.collectingAndThen(Collectors.toMap(e -> Arrays.asList(e.getOid(), e.getOtype()), e -> e, (existing, replacement) -> existing), map -> new ArrayList<>(map.values())));
                    List<ChgActRecordLinkDO> distLinkList = chgActRecordLinkDOList.stream().collect(Collectors.collectingAndThen(Collectors.toMap(e -> Arrays.asList(e.getOid(), e.getOtype()), e -> e, (existing, replacement) -> existing), map -> new ArrayList<>(map.values())));
                    //添加变更前对象
                    if (CollUtil.isNotEmpty(distEntityList)) {
                        ECAddChangeObjectDTO ecAddChangeObjectDTO = new ECAddChangeObjectDTO();
                        ecAddChangeObjectDTO.setEntityList(distEntityList);
                        ecAddChangeObjectDTO.setBefore(true);
                        ecAddChangeObjectDTO.setSaveDataBase(false);
                        ecAddChangeObjectDTO.setEntity(new IdentifierEntity(flowChgFormView.getBaseObjectOid(), "ty.inteplm.change.CTyChangeNotice"));
                        this.typlmEngineeringChangeService.addBeforeChangeObjectWithStrategy(ecAddChangeObjectDTO);
                    }
                    //添加变更后对象
                    if (CollUtil.isNotEmpty(distLinkList)) {
                        this.typlmChgActRecordLinkService.batchInsertSelective(distLinkList);
                    }
                }
            }
        }
    }

    /**
     * 构建变更前对象
     *
     * @param id
     * @param type
     * @param entityList
     */
    public void buildEcABeforeVOListByOid(String id, String type, List<ECObjDTO> entityList) {
        if (StringUtils.isNotBlank(type) && StringUtils.isNotBlank(id)) {
            String tableName = "";
            if (RTPlmConstant.PART_TYPE.equals(type)) {
                tableName = "ty_part";
            } else if (RTPlmConstant.CADDOC_TYPE.equals(type)) {
                tableName = "ty_caddoc";
            } else if (RTPlmConstant.DOC_TYPE.equals(type)) {
                tableName = "ty_doc";
            }
            JSONObject jsonObject = this.rtChangeMapper.getObjectByOid(tableName, id);
            String uid = jsonObject.getString("CREATOROID");
            String utype = jsonObject.getString("CREATOROTYPE");
            //收集变更前对象
            ECObjDTO entity = new ECObjDTO();
            entity.setOid(new BigInteger(id));
            entity.setOtype(type);
            entity.setOwnerOid(new BigInteger(uid));
            entity.setOwnerOtype(utype);
            entity.setChangeStrategy("Change");
            entityList.add(entity);
        }
    }

    /**
     * 构建变更前对象
     *
     * @param beforeChangeNo
     * @param entityList
     */
    public void buildEcABeforeVOListByNumber(String beforeChangeNo, List<ECObjDTO> entityList, String type, String view) {
        JSONObject beforeChangeNoJson = null;
        if ("图纸升版".equals(type)) {
            beforeChangeNoJson = this.rtChangeMapper.querySecLatestMaterialByCode(beforeChangeNo, view);
        } else {
            beforeChangeNoJson = this.rtChangeMapper.queryLatestMaterialByCode(beforeChangeNo, view);
        }

        if (beforeChangeNoJson != null) {
            String id = beforeChangeNoJson.getString("OID");
            String otype = beforeChangeNoJson.getString("OTYPE");
            JSONObject jsonObject = this.rtChangeMapper.getObjectByOid("ty_part", id);
            String uid = jsonObject.getString("CREATOROID");
            String utype = jsonObject.getString("CREATOROTYPE");
            //收集变更前对象
            ECObjDTO ecObjDTO = new ECObjDTO();
            ecObjDTO.setOid(new BigInteger(id));
            ecObjDTO.setOtype(otype);
            ecObjDTO.setOwnerOid(new BigInteger(uid));
            ecObjDTO.setOwnerOtype(utype);
            ecObjDTO.setChangeStrategy("Change");
            ecObjDTO.setIdentifierRef(new IdentifierEntity(new BigInteger(id), otype));
            entityList.add(ecObjDTO);
        }
    }

    /**
     * 构建变更后对象
     *
     * @param chgActivityDO
     * @param afterChangeNo
     * @param chgActRecordLinkDOList
     */
    public void buildEcAffectVOList(ChgActivityDO chgActivityDO, String afterChangeNo, List<ChgActRecordLinkDO> chgActRecordLinkDOList, String view) {
        JSONObject afterChangeNoJson = this.rtChangeMapper.queryLatestMaterialByCode(afterChangeNo, view);
        if (afterChangeNoJson != null) {
            String id = afterChangeNoJson.getString("OID");
            String otype = afterChangeNoJson.getString("OTYPE");
            List<DocDetails> docDetails = this.typlmPartRelObjectService.queryPartRelatedDocInfo(new BigInteger(id));
            if (docDetails != null) {
                for (DocDetails docDetail : docDetails) {
                    ChgActRecordLinkDO chgActRecordLinkDO = new ChgActRecordLinkDO();
                    chgActRecordLinkDO.setAoid(chgActivityDO.getOid());
                    chgActRecordLinkDO.setAotype(chgActivityDO.getOtype());
                    chgActRecordLinkDO.setBoid(new BigInteger(docDetail.getOid()));
                    chgActRecordLinkDO.setBotype(docDetail.getOtype());
                    chgActRecordLinkDO.setOid(snowflakeIdComponent.getInstance().nextId());
                    chgActRecordLinkDO.setOtype(TableTypeConstrant.TY_CHGACTRECORDLINK_OTYPE);
                    chgActRecordLinkDO.setBranchid(chgActivityDO.getBranchid());
                    TyplmEntityBaseUtil.fillCommonFieldForCreate(chgActRecordLinkDO);
                    chgActRecordLinkDOList.add(chgActRecordLinkDO);
                }
            }
            ChgActRecordLinkDO chgActRecordLinkDO = new ChgActRecordLinkDO();
            chgActRecordLinkDO.setAoid(chgActivityDO.getOid());
            chgActRecordLinkDO.setAotype(chgActivityDO.getOtype());
            chgActRecordLinkDO.setBoid(new BigInteger(id));
            chgActRecordLinkDO.setBotype(otype);
            chgActRecordLinkDO.setOid(snowflakeIdComponent.getInstance().nextId());
            chgActRecordLinkDO.setOtype(TableTypeConstrant.TY_CHGACTRECORDLINK_OTYPE);
            chgActRecordLinkDO.setBranchid(chgActivityDO.getBranchid());
            TyplmEntityBaseUtil.fillCommonFieldForCreate(chgActRecordLinkDO);
            chgActRecordLinkDOList.add(chgActRecordLinkDO);
        }
    }

    public void buildEcAffectVODrawList(ChgActivityDO chgActivityDO, String oid, String otype, List<ChgActRecordLinkDO> chgActRecordLinkDOList, String view) {
        ChgActRecordLinkDO chgActRecordLinkDO = new ChgActRecordLinkDO();
        chgActRecordLinkDO.setAoid(chgActivityDO.getOid());
        chgActRecordLinkDO.setAotype(chgActivityDO.getOtype());
        chgActRecordLinkDO.setBoid(new BigInteger(oid));
        chgActRecordLinkDO.setBotype(otype);
        chgActRecordLinkDO.setOid(snowflakeIdComponent.getInstance().nextId());
        chgActRecordLinkDO.setOtype(TableTypeConstrant.TY_CHGACTRECORDLINK_OTYPE);
        chgActRecordLinkDO.setBranchid(chgActivityDO.getBranchid());
        TyplmEntityBaseUtil.fillCommonFieldForCreate(chgActRecordLinkDO);
        chgActRecordLinkDOList.add(chgActRecordLinkDO);
    }

    /**
     * @param workFlowContainerId
     * @throws Exception
     */
    @Override
    public void checkRelateECRStatus(String workFlowContainerId) {
        StringBuffer sb = new StringBuffer();
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && workFlowContainerView instanceof FlowChgFormView) {
            log.info("当前流程属于变更通告流程");
            FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
            ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
            ChgNoticeDO chgNoticeDO = this.typlmChgNoticeQueryService.selectByPrimaryKey(chgFormVO.getOid());
            if (Objects.isNull(chgNoticeDO)) {
                TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_OBJECT_NOT_FOUND, new String[]{chgFormVO.getOid().toString()});
            }
            List<ChgRequestVO> list = typlmChangeLinkService.queryECRByECO(chgNoticeDO);
            if (CollUtil.isNotEmpty(list)) {
                for (ChgRequestVO chgRequestVO : list) {
                    String lifecycleStatus = chgRequestVO.getLifecyclestagekey();
                    boolean objInActiveFlowContainer = this.typlmFlowContainerObjectService.checkObjInActiveFlowContainer(chgRequestVO.getOid(), chgRequestVO.getOtype());
                    if (objInActiveFlowContainer) {
                        sb.append("编码为").append(chgRequestVO.getMasterNumber()).append("的变更请求流程未结束; \n");
                    }
                }
            }
        }
        if (StringUtils.isNotBlank(sb.toString())) {
            throw RTErrorCodeEnum.CHANGEREQUEST_INCOMPLETE_EXCEPTION.getException(sb.toString());
        }
    }

    /**
     * 校验变更对象是否符合变更要求（状态为已发布，且是非检出）
     *
     * @param workFlowContainerId
     * @throws Exception
     */
    @Override
    public void checkChangeStatus(String workFlowContainerId, String targetStatusKey) {
        errorList = new ArrayList();
        List<String> afterMsgList = new ArrayList();
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        StringBuffer sb = new StringBuffer();
        if (!Objects.isNull(workFlowContainerView) && workFlowContainerView instanceof FlowChgFormView) {
            if (workFlowContainerView instanceof FlowChangeIssueView) {

            } else if (workFlowContainerView instanceof FlowChangeRequestView) {
                FlowChangeRequestView flowChangeRequestView = (FlowChangeRequestView) workFlowContainerView;
                //获取变更请求对象
                ChgRequestDetailVO chgRequestDetailVO = flowChangeRequestView.getChgRequestDetailVO();
                List<ECLinkObjDataCommonVO> eclinkObjList = this.typlmEcAgainstDataService.batchGetAffectedObjectListByOids(Collections.singletonList(chgRequestDetailVO.getOid()), chgRequestDetailVO.getOtype());
                if (CollectionUtils.isNotEmpty(eclinkObjList)) {
                    for (ECLinkObjDataCommonVO dataCommonVO : eclinkObjList) {
                        String statusKey = dataCommonVO.getLifeCycleStageKeyName();
                        String number = dataCommonVO.getObjectNumber();
                        String typeDefName = dataCommonVO.getTypeDefName();
                        sb = new StringBuffer();
                        if (!targetStatusKey.contains(statusKey)) {
                            errorList.add(sb.append("编码为").append(number).append("的").append(typeDefName).toString());
                        }
                    }
                }
            } else if (workFlowContainerView instanceof FlowChgFormView) {
                log.info("当前流程属于变更通告流程");
                FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
                List<ECObjData> ecObjDataVOS = chgFormVO.getEcObjDataVOS();
                List<ECObjData> afterDataVOS = chgFormVO.getEcAffectVOS();
                if (CollectionUtils.isEmpty(ecObjDataVOS)) {
                    return;
                }
                for (ECObjData ecObjData : ecObjDataVOS) {
                    String statusKey = ecObjData.getLifecycleStageKey();
                    String number = ecObjData.getObjectNumber();
                    String typeDefName = ecObjData.getTypeDefName();
                    sb = new StringBuffer();
                    if (!targetStatusKey.contains(statusKey)) {
                        errorList.add(sb.append("编码为").append(number).append("的").append(typeDefName).toString());
                    }
                }
                if (CollectionUtils.isNotEmpty(afterDataVOS)) {
                    for (ECObjData afterDataVO : afterDataVOS) {
                        String statusKey = afterDataVO.getLifecycleStageKey();
                        String number = afterDataVO.getObjectNumber();
                        String typeDefName = afterDataVO.getTypeDefName();
                        if ("DISABLED".equalsIgnoreCase(statusKey)) {
                            afterMsgList.add(sb.append("编码为").append(number).append("的").append(typeDefName).toString());
                        }
                    }
                }
            }
        }
        if (errorList.size() > 0) {
            throw RTErrorCodeEnum.CUSTOM_EXCEPTION.getException(new Object[]{StringUtils.join(errorList, ";")} + "状态不是已生效或变更中，请检查！");
        }
        if (afterMsgList.size() > 0) {
            throw RTErrorCodeEnum.CUSTOM_EXCEPTION.getException(new Object[]{StringUtils.join(afterMsgList, ";")} + "状态已失效，不能添加到变更后对象中！");
        }
    }

    /**
     * @param workFlowContainerId
     * @throws Exception
     */
    @Override
    public void updateAppointSupplier(String workFlowContainerId) throws Exception {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && (workFlowContainerView instanceof FlowChgFormView || workFlowContainerView instanceof FlowChangeRequestView)) {
            log.info("当前流程属于变更通告流程");
            //表单内容
            String formData = "";
            if (workFlowContainerView instanceof FlowChgFormView) {
                FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                //获取变更通告对象
                ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
//                List<ChgActivityDO> chgActivityDOList = this.typlmChgNoticeActivityLinkService.queryECAByECNId(chgFormVO.getOid());
                String changeNo = chgFormVO.getObjectNumber();
                //获取变更表单数据
                formData = chgFormVO.getFormData();
                if (StringUtils.isNotBlank(formData)) {
                    JSONObject formDataJson = JSONObject.parseObject(formData);
                    JSONArray subform47946 = formDataJson.getJSONArray("subform47946");
                    JSONArray subform57714 = formDataJson.getJSONArray("subform57714");
                    //受影响的成品BOM
                    List<RtChangeaffectFinishedbomDO> finishedbomDOS = this.rtChangeaffectFinishedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                    //关联受影响的BOM
                    List<RtChangeaffectAssociatedbomDO> associatedbomDOS = this.rtChangeaffectAssociatedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                    List<JSONObject> jsonList = new ArrayList<>();
                    if (CollectionUtils.isNotEmpty(finishedbomDOS)) {
                        for (RtChangeaffectFinishedbomDO finishedbomDO : finishedbomDOS) {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("partNumber", finishedbomDO.getPartnumber());
                            jsonObject.put("productCode", finishedbomDO.getFinishedproductcode());
                            jsonObject.put("materialCode", finishedbomDO.getMaterialcode());
                            jsonObject.put("factory", finishedbomDO.getProductioninvietnam());
                            jsonList.add(jsonObject);
                        }
                    }
                    if (CollectionUtils.isNotEmpty(associatedbomDOS)) {
                        associatedbomDOS = associatedbomDOS.stream().filter(e -> !RTPlmConstant.PATTERNCODE.equals(e.getParttype())).collect(Collectors.toList());
                        for (RtChangeaffectAssociatedbomDO associatedbomDO : associatedbomDOS) {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("partNumber", associatedbomDO.getPartnumber());
                            jsonObject.put("productCode", associatedbomDO.getCode());
                            jsonObject.put("materialCode", associatedbomDO.getMaterialCode());
                            jsonObject.put("factory", associatedbomDO.getMadeVietnam());
                            jsonList.add(jsonObject);
                        }
                    }
                    //关联受影响的MBOM
//                  List<RtChangeaffectMbomDO> mbomDOS = this.rtChangeaffectMbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                    List<JSONObject> appiontList = new ArrayList<>();
                    if (CollectionUtils.isEmpty(jsonList))
                        return;
                    for (JSONObject json : jsonList) {
                        String partNumber = json.getString("partNumber");
                        String productCode = json.getString("productCode");
                        String materialcode = json.getString("materialCode");
                        String factory = json.getString("factory");
                        if (CollectionUtils.isNotEmpty(subform47946)) {
                            //图纸更改
                            for (int i = 0; i < subform47946.size(); i++) {
                                String type = subform47946.getJSONObject(i).get("radio81926").toString();
                                String beforeChangeNo = subform47946.getJSONObject(i).getString("input67563");
                                String afterChangeNo = subform47946.getJSONObject(i).getString("radio73127");
                                if (StringUtils.isNotBlank(afterChangeNo) && afterChangeNo.contains(",")) {
                                    afterChangeNo = afterChangeNo.split(",")[0];
                                }
                                if ("图号升级".equals(type)) {
                                    if (beforeChangeNo.equals(partNumber)) {
                                        afterChangeNo = afterChangeNo.concat(materialcode.substring(materialcode.lastIndexOf("-")));
                                        JSONObject materialCodeJson = this.rtChangeMapper.queryMaterialByCodeAndType(afterChangeNo, RTPlmConstant.MATERIALCODE, RTPlmConstant.VIEW_DESIGN);
                                        if (materialCodeJson != null) {
                                            JSONObject productJson = this.rtChangeMapper.queryMaterialByCodeAndType(productCode, RTPlmConstant.PRODUCTCODE, RTPlmConstant.VIEW_DESIGN);
                                            if (productJson != null) {
                                                String oid = productJson.getString("OID");
                                                String otype = productJson.getString("OTYPE");
                                                String customer = this.rtChangeMapper.queryIBAValueByOidAndOtype(oid, otype, RTPlmConstant.CUSTOMERCODE);
                                                String DevelopmentOrder = this.rtChangeMapper.queryIBAValueByOidAndOtype(oid, otype, RTPlmConstant.DevelopmentOrder);
//                                                String factory = this.rtChangeMapper.queryIBAValueByOidAndOtype(oid, otype, "factory");
                                                JSONObject tempJson = new JSONObject();
                                                tempJson.put("type", type);
                                                tempJson.put("beforeChangeNo", materialcode);
                                                tempJson.put("afterChangeNo", afterChangeNo);
                                                tempJson.put("customer", customer);
                                                tempJson.put("DevelopmentOrder", DevelopmentOrder);
                                                tempJson.put("factory", factory);
                                                tempJson.put("productCode", productCode);
                                                appiontList.add(tempJson);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    for (JSONObject json : jsonList) {
                        String partNumber = json.getString("partNumber");
                        String productCode = json.getString("productCode");
                        String materialcode = json.getString("materialCode");
                        String factory = json.getString("factory");
                        for (int i = 0; i < subform57714.size(); i++) {
                            String type = subform57714.getJSONObject(i).get("input70284").toString();
                            String beforeChangeNo = subform57714.getJSONObject(i).getString("input36063");
                            String afterChangeNo = subform57714.getJSONObject(i).getString("input37516");
                            if (type.equals("修改") || type.equals("替换")) {
                                if (beforeChangeNo.equals(partNumber)) {
                                    JSONObject materialCodeJson = this.rtChangeMapper.queryMaterialByCodeAndType(afterChangeNo, RTPlmConstant.MATERIALCODE, RTPlmConstant.VIEW_DESIGN);
                                    String childOid = materialCodeJson.getString("OID");
                                    String childOtype = materialCodeJson.getString("OTYPE");
                                    if (materialCodeJson != null) {
                                        JSONObject productJson = this.rtChangeMapper.queryMaterialByCodeAndType(productCode, RTPlmConstant.PRODUCTCODE, RTPlmConstant.VIEW_DESIGN);
                                        if (productJson != null) {
                                            String oid = productJson.getString("OID");
                                            String otype = productJson.getString("OTYPE");
                                            String customer = this.rtChangeMapper.queryIBAValueByOidAndOtype(oid, otype, RTPlmConstant.CUSTOMERCODE);
                                            String DevelopmentOrder = this.rtChangeMapper.queryIBAValueByOidAndOtype(oid, otype, RTPlmConstant.DevelopmentOrder);
                                            String hasSendSAP = this.rtChangeMapper.queryIBAValueByOidAndOtype(childOid, childOtype, RTPlmConstant.ALREADYSENDSAP);
                                            JSONObject tempJson = new JSONObject();
                                            tempJson.put("type", type);
                                            tempJson.put("beforeChangeNo", materialcode);
                                            tempJson.put("afterChangeNo", afterChangeNo);
                                            tempJson.put("hasSendSAP", hasSendSAP);
                                            tempJson.put("customer", customer);
                                            tempJson.put("DevelopmentOrder", DevelopmentOrder);
                                            tempJson.put("factory", factory);
                                            tempJson.put("productCode", productCode);
                                            appiontList.add(tempJson);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    String err = appointBatchUpdate(appiontList);
                    if (StringUtils.isNotBlank(err)) {
                        throw RTErrorCodeEnum.UPDATE_APPOINT_ERROR.getException(err);
                    }
                }
            }
        }
    }

    /**
     * @param workFlowContainerId
     * @throws Exception
     */
    @Override
    public void refreshStatusRequire(String workFlowContainerId) throws Exception {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && (workFlowContainerView instanceof FlowChgFormView || workFlowContainerView instanceof FlowChangeRequestView)) {
            log.info("当前流程属于变更通告流程");
            //表单内容
            String formData = "";
            if (workFlowContainerView instanceof FlowChgFormView) {
                FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                //获取变更通告对象
                ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
                String changeNo = chgFormVO.getObjectNumber();
                formData = chgFormVO.getFormData();
                List<ECObjData> affectVOS = chgFormVO.getEcAffectVOS();
                if (CollectionUtils.isEmpty(affectVOS)) {
                    return;
                }
                List<ECObjData> productVOS = affectVOS.stream().filter(ecObjData -> "成品码".equals(ecObjData.getTypeDefName())).collect(Collectors.toList());
                if (StringUtils.isNotBlank(formData)) {
                    JSONObject formDataJson = JSONObject.parseObject(formData);
                    JSONArray subform47946 = formDataJson.getJSONArray("subform47946");
                    JSONArray subform57714 = formDataJson.getJSONArray("subform57714");
                    if (CollectionUtils.isNotEmpty(subform47946)) {
                        //图纸更改
                        for (int i = 0; i < subform47946.size(); i++) {
                            String type = subform47946.getJSONObject(i).get("radio81926").toString();
                            String beforeChangeNo = subform47946.getJSONObject(i).getString("input67563");
                            String afterChangeNo = subform47946.getJSONObject(i).getString("radio73127");
                            if (StringUtils.isNotBlank(afterChangeNo) && afterChangeNo.contains(",")) {
                                afterChangeNo = afterChangeNo.split(",")[0];
                            }
                            String radio38347 = subform47946.getJSONObject(i).getString("radio38347");
                            if (StringUtils.isNotBlank(radio38347) && radio38347.contains(",")) {
                                radio38347 = radio38347.split(",")[0];
                            }
                            //判断是否更改描述
                            if ("是".equals(radio38347)) {
                                //受影响的成品BOM
                                List<RtChangeaffectFinishedbomDO> finishedbomDOS = this.rtChangeaffectFinishedbomMapper.queryByChangeNoAndPartNo(changeNo, beforeChangeNo);
                                if (CollectionUtils.isNotEmpty(finishedbomDOS)) {
                                    List<RtChangeaffectFinishedbomDO> productBomDOS = finishedbomDOS.stream().filter(finishedbomDO -> beforeChangeNo.equals(finishedbomDO.getPartnumber())).collect(Collectors.toList());
                                    if ("图号升级".equals(type)) {
                                        for (RtChangeaffectFinishedbomDO finishedbomDO : productBomDOS) {
                                            String productCode = finishedbomDO.getFinishedproductcode();
                                            String requireCode = finishedbomDO.getStatusrequiretable();
                                            String devCode = finishedbomDO.getDevelopmentorder();
                                            String model = finishedbomDO.getModel();
                                            String materialCode = finishedbomDO.getMaterialcode();
                                            String categoryNo = "";
                                            String colorNo = "";
                                            if ("H".equals(materialCode.charAt(5))) {
                                                categoryNo = materialCode.substring(0, 5);
                                                colorNo = materialCode.split("-")[1];
                                            } else {
                                                categoryNo = materialCode.split("-")[0];
                                                colorNo = materialCode.split("-")[2];
                                            }
                                            String newPartNum = afterChangeNo + "-" + colorNo;
                                            if (StringUtils.isBlank(model) || StringUtils.isBlank(devCode)) continue;
                                            RtCfgStatusDTO statusDTO = new RtCfgStatusDTO();
                                            statusDTO.setProducttype(model);
                                            statusDTO.setDevcode(devCode);
                                            ResponseResult result = this.dspfStatusModuleitemsubService.getStatusModuleitemsubList(statusDTO);
                                            String requestStatus = result.getCode();
                                            if ("200".equals(requestStatus)) {
                                                Object data = result.getData();
                                                List<DspfStatusModultitemsubVO> modultitemsubVOS = new ArrayList<>();
                                                if (data != null) {
                                                    JSONArray array = (JSONArray) data;
                                                    if (CollectionUtils.isNotEmpty(array)) {
                                                        for (Object object : array) {
                                                            modultitemsubVOS = getAttributeValue(modultitemsubVOS, (JSONObject) object, newPartNum);
                                                        }
                                                    }
                                                }
                                                if (CollectionUtils.isNotEmpty(modultitemsubVOS)) {
                                                    RtCfgBOMAndStatusInfoDTO rtCfgBOMAndStatusInfoDTO = new RtCfgBOMAndStatusInfoDTO();
                                                    rtCfgBOMAndStatusInfoDTO.setStatusCode(requireCode);
                                                    rtCfgBOMAndStatusInfoDTO.setProducttype(model);
                                                    rtCfgBOMAndStatusInfoDTO.setDescrList(modultitemsubVOS);
                                                    this.rtCfgStatusInfoService.customization(rtCfgBOMAndStatusInfoDTO);
                                                }
                                            }
                                        }
                                    } else if ("图纸升版".equals(type)) {
//                                        for (RtChangeaffectFinishedbomDO finishedbomDO : productBomDOS) {
//                                            String productCode = finishedbomDO.getFinishedproductcode();
//                                            String requireCode = finishedbomDO.getStatusrequiretable();
//                                            String devCode = finishedbomDO.getDevelopmentorder();
//                                            String model = finishedbomDO.getModel();
//                                            String materialCode = finishedbomDO.getMaterialcode();
//                                            String categoryNo = "";
//                                            String colorNo = "";
//                                            if ("H".equals(materialCode.charAt(5))) {
//                                                categoryNo = materialCode.substring(0, 5);
//                                                colorNo = materialCode.split("-")[1];
//                                            } else {
//                                                categoryNo = materialCode.split("-")[0];
//                                                colorNo = materialCode.split("-")[2];
//                                            }
//                                            String newPartNum = afterChangeNo + "-" + colorNo;
//                                            RtCfgStatusDTO statusDTO = new RtCfgStatusDTO();
//                                            statusDTO.setProducttype(model);
//                                            statusDTO.setProductCode(categoryNo);
//                                            ResponseResult result = this.dspfStatusModuleitemsubService.getStatusModuleitemsubList(statusDTO);
//                                            String requestStatus = result.getCode();
//                                            if ("200".equals(requestStatus)) {
//                                                Object data = result.getData();
//                                                List<DspfStatusModultitemsubVO> modultitemsubVOS = new ArrayList<>();
//                                                if (data != null) {
//                                                    JSONArray array = (JSONArray) data;
//                                                    if (CollectionUtils.isNotEmpty(array)) {
//                                                        for (Object object : array) {
//                                                            modultitemsubVOS = getAttributeValue(modultitemsubVOS, (JSONObject) object, newPartNum);
//                                                        }
//                                                    }
//                                                }
//                                                if (CollectionUtils.isNotEmpty(modultitemsubVOS)) {
//                                                    RtCfgBOMAndStatusInfoDTO rtCfgBOMAndStatusInfoDTO = new RtCfgBOMAndStatusInfoDTO();
//                                                    rtCfgBOMAndStatusInfoDTO.setStatusCode(requireCode);
//                                                    rtCfgBOMAndStatusInfoDTO.setProducttype(model);
//                                                    rtCfgBOMAndStatusInfoDTO.setDescrList(modultitemsubVOS);
//                                                    this.rtCfgStatusInfoService.customization(rtCfgBOMAndStatusInfoDTO);
//                                                }
//                                            }
//                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (CollectionUtils.isNotEmpty(subform57714)) {
                        //关联变更件替换说明
                        for (int i = 0; i < subform57714.size(); i++) {
//                            String type = subform57714.getJSONObject(i).get("radio74373").toString();
                            String type = subform57714.getJSONObject(i).getString("input70284");
                            String beforeChangeNo = subform57714.getJSONObject(i).getString("input36063");
                            String afterChangeNo = subform57714.getJSONObject(i).getString("input37516");
                            String radio76812 = subform57714.getJSONObject(i).getString("radio76812");
                            if (StringUtils.isNotBlank(radio76812) && radio76812.contains(",")) {
                                radio76812 = radio76812.split(",")[0];
                            }
//                            if (!"是".equals(radio76812))
//                                continue;
                            if (type.equals("修改") || type.equals("替换")) {
                                //关联受影响的BOM
                                List<RtChangeaffectAssociatedbomDO> associatedbomDOS = this.rtChangeaffectAssociatedbomMapper.queryByChangeNoAndPartNo(changeNo, beforeChangeNo);
                                if (CollectionUtils.isNotEmpty(associatedbomDOS)) {
                                    List<RtChangeaffectAssociatedbomDO> productBomDOS = associatedbomDOS.stream().filter(finishedbomDO -> beforeChangeNo.equals(finishedbomDO.getPartnumber()) && "成品码".equals(finishedbomDO.getBomtype())).collect(Collectors.toList());
                                    if (CollectionUtils.isNotEmpty(productBomDOS)) {
                                        for (RtChangeaffectAssociatedbomDO associatedbomDO : productBomDOS) {
                                            String productCode = associatedbomDO.getCode();
                                            String requireCode = associatedbomDO.getStatusRequireCode();
                                            String devCode = associatedbomDO.getDevCode();
                                            String model = associatedbomDO.getProductType();
                                            String materialCode = associatedbomDO.getMaterialCode();
                                            String categoryNo = "";
                                            String colorNo = "";
                                            if ("H".equals(materialCode.charAt(5))) {
                                                categoryNo = materialCode.substring(0, 5);
                                                colorNo = materialCode.split("-")[1];
                                            } else {
                                                categoryNo = materialCode.split("-")[0];
                                                colorNo = materialCode.split("-")[2];
                                            }
                                            String newPartNum = afterChangeNo + "-" + colorNo;
                                            RtCfgStatusDTO statusDTO = new RtCfgStatusDTO();
                                            statusDTO.setProducttype(model);
                                            statusDTO.setDevcode(devCode);
                                            ResponseResult result = this.dspfStatusModuleitemsubService.getStatusModuleitemsubList(statusDTO);
                                            String requestStatus = result.getCode();
                                            if ("200".equals(requestStatus)) {
                                                Object data = result.getData();
                                                List<DspfStatusModultitemsubVO> modultitemsubVOS = new ArrayList<>();
                                                if (data != null) {
                                                    JSONArray array = (JSONArray) data;
                                                    if (CollectionUtils.isNotEmpty(array)) {
                                                        for (Object object : array) {
                                                            modultitemsubVOS = getAttributeValue(modultitemsubVOS, (JSONObject) object, newPartNum);
                                                        }
                                                    }
                                                }
                                                if (CollectionUtils.isNotEmpty(modultitemsubVOS)) {
                                                    RtCfgBOMAndStatusInfoDTO rtCfgBOMAndStatusInfoDTO = new RtCfgBOMAndStatusInfoDTO();
                                                    rtCfgBOMAndStatusInfoDTO.setStatusCode(requireCode);
                                                    rtCfgBOMAndStatusInfoDTO.setProducttype(model);
                                                    rtCfgBOMAndStatusInfoDTO.setDescrList(modultitemsubVOS);
                                                    this.rtCfgStatusInfoService.customization(rtCfgBOMAndStatusInfoDTO);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * 修改零部件状态
     *
     * @param ecnId
     * @param targetLifeCycleStateKey
     */
    @Override
    public void setEcnRelevanceChgAfterObjectSpecifyState(BigInteger ecnId, String targetLifeCycleStateKey) {
        ChgNoticeDO chgNoticeDO = this.typlmChgNoticeQueryService.selectByPrimaryKey(ecnId);
        List<ChgActivityVO> chgActivityVOList = this.typlmChangeLinkService.queryECAByECO(chgNoticeDO);
        List<ECObjDataVO> drawDataList = new ArrayList<>();
        List<BigInteger> oidList = new ArrayList<>();
        if (!CollUtil.isEmpty(chgActivityVOList)) {
            List<CTyEntityBaseDO> updateList = new ArrayList();
            for (ChgActivityVO chgActivityVO : chgActivityVOList) {
                List<ECObjDataVO> beforeDataLinkList = this.typlmChangeObjectLinkService.queryECObjList(new IdentifierEntity(chgActivityVO.getOid(), chgActivityVO.getOtype()), Boolean.TRUE);
                drawDataList.addAll(beforeDataLinkList.stream().filter(item -> TableTypeConstrant.TY_CADDOC_OTYPE.equals(item.getOtype())).collect(Collectors.toList()));
                if (CollUtil.isNotEmpty(beforeDataLinkList)) {
                    for (ECObjDataVO ecObjDataVO : beforeDataLinkList) {
                        String typedefName = ecObjDataVO.getTypeDefName();
                        if ("图样代号".equals(typedefName) || "物料码".equals(typedefName) || "标准件".equals(typedefName)) {
                            BigInteger oid = ecObjDataVO.getOid();
                            String otype = ecObjDataVO.getOtype();
                            oidList.add(oid);
                            List<PartDO> childPartIds = rtChangeMapper.queryChildPart(String.valueOf(oid), RTPlmConstant.VIEW_DESIGN);
                            if (CollUtil.isNotEmpty(childPartIds)) {
                                continue;
                            }
                            CTyEntityBaseDO entity = CommonUtil.getEntity(new IdentifierEntity(oid, otype));
                            updateList.add(entity);
                        }
                    }
                }
            }
            if (CollUtil.isNotEmpty(oidList) && CollUtil.isNotEmpty(drawDataList)) {
                oidList.forEach(oid -> {
                    List<DocDetails> docDetails = this.typlmPartRelObjectService.queryPartRelatedDocInfo(oid);
                    for (DocDetails docDetail : docDetails) {
                        if (drawDataList.stream().anyMatch(item -> item.getObjectNumber().equals(docDetail.getObjectNumber()))) {
                            CTyEntityBaseDO entity = CommonUtil.getEntity(new IdentifierEntity(new BigInteger(docDetail.getOid()), docDetail.getOtype()));
                            updateList.add(entity);
                        }
                    }
                });
            }
            if (CollUtil.isNotEmpty(updateList)) {
                // 批量更新生命周期状态
                this.typlmCommonLifecycleService.batchUpdateEntityLifecycle(updateList, targetLifeCycleStateKey, true, true);
            }
        }
    }

    /**
     * @param workFlowContainerId
     */
    @Override
    public void setSecVersionStatus(BigInteger workFlowContainerId, String targetLifeCycleStateKey) {
        if (workFlowContainerId == null) {
            return;
        }
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(workFlowContainerId);
        if (workFlowContainerView instanceof WorkFlowObjectPackage) {
            WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage) workFlowContainerView;
            List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
            List<EntityLifeCycleDTO> entityLifeCycleList = new ArrayList();
            TyplmCommonLifecycleService typlmCommonLifecycleService = (TyplmCommonLifecycleService) SpringUtil.getBean(TyplmCommonLifecycleService.class);
            for (FlowObject flowObject : flowObjectList) {
                String typeDefName = flowObject.getType();
                String view = flowObject.getRefObjectView();
                String refObjectNumber = flowObject.getRefObjectNumber();
                String objectOtype = flowObject.getRefObjectOtype();
                BigInteger objectOid = flowObject.getRefObjectOid();
                if (RTPlmConstant.PART_TYPE.equals(objectOtype)) {
                    JSONObject json = rtChangeMapper.querySecLatestMaterialByCode(refObjectNumber, view);
                    if (json != null) {
                        String oid = json.getString("OID");
                        String otype = json.getString("OTYPE");

                        EntityLifeCycleDTO entityLifeCycleDTO = new EntityLifeCycleDTO();
                        entityLifeCycleDTO.setOid(new BigInteger(oid));
                        entityLifeCycleDTO.setOtype(otype);
                        entityLifeCycleDTO.setLifeCycleStageKey(targetLifeCycleStateKey);
                        entityLifeCycleList.add(entityLifeCycleDTO);
                    }
                }
            }
            this.setProcessObjectLife("Y", targetLifeCycleStateKey, entityLifeCycleList);
            typlmCommonLifecycleService.batchUpdateEntityLifecycle(entityLifeCycleList, true, true);
        }
    }

    /**
     * 流程分支控制
     *
     * @param workFlowContainerId
     * @param conditionBranch
     */
    @Override
    public void setBranchControl(BigInteger workFlowContainerId, String conditionBranch, DelegateExecution execution) {
        if (workFlowContainerId == null) {
            return;
        }
        String value = "";
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(workFlowContainerId);
        if (workFlowContainerView instanceof FlowChgFormView) {
            FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
            //获取变更通告对象
            ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
            BigInteger createrId = chgFormVO.getCreatorOid();
            List<String> createDepartMent = getUserDepartMent(createrId);
            String changeNo = chgFormVO.getObjectNumber();
            String formData = chgFormVO.getFormData();
            if (changeNo.contains("RTTJXM")) {
                //修模通知单
                //                batchProduction 量产前后
                //                moldCost 修模费用
                //                factory 产地
                if (StringUtils.isNotBlank(formData)) {
                    JSONObject formDataJson = JSONObject.parseObject(formData);
                    JSONObject testObj = formDataJson.getJSONObject("testObj");
                    String batchProduction = testObj.getString("batchProduction");
                    String moldCost = testObj.getString("moldCost");
                    int cost = Integer.parseInt(moldCost);
                    String factoryStr = testObj.getString("factory");
                    JSONArray factorys = JSONArray.parseArray(factoryStr);
                    JSONArray conditionArray = JSONArray.parseArray(conditionBranch);
                    for (int i = 0; i < conditionArray.size(); i++) {
                        JSONObject jsonObject = conditionArray.getJSONObject(i);
                        String branchName = jsonObject.getString("branchName");
                        String condition = jsonObject.getString("condition");
                        value = covrentCondition(branchName, condition, createDepartMent, cost, factorys);
                        if (StringUtils.isNotBlank(value)) {
                            execution.setVariable("param", value);
                            break;
                        }
                    }
                }
            } else if (changeNo.contains("RTTJJG")) {
                //订单更改通知单
                JSONObject formDataJson = JSONObject.parseObject(formData);
                JSONObject testObj = formDataJson.getJSONObject("testObj");
                String ZJCD = testObj.getString("ZJCD");//整机产地
                Map<String, String> enmumap = typlmEnumerationService.getEnabledEnumItemsMap(Collections.singletonList("factory")).get("factory");
                ZJCD = cqrtplm.util.CommonUtil.covertFactory(ZJCD, enmumap);
                cqrtplm.util.CommonUtil.setJGExecutionVariable(chgFormVO, conditionBranch, execution);
            } else if (changeNo.contains("RTTJST")) {
                //设计更改通知单
                cqrtplm.util.CommonUtil.setSTExecutionVariable(chgFormVO, conditionBranch, execution);
            }
        } else if (workFlowContainerView instanceof FlowChangeRequestView) {
            FlowChangeRequestView flowChangeRequestView = (FlowChangeRequestView) workFlowContainerView;
            //获取变更请求对象
            ChgRequestDetailVO reqDetailVO = flowChangeRequestView.getChgRequestDetailVO();
            String formData = reqDetailVO.getFormData();
            if (StringUtils.isNotBlank(formData)) {
                JSONObject json = JSONObject.parseObject(formData);
                JSONArray subform47946 = json.getJSONArray("subform47946");
                boolean isDrawModify = false;
                boolean isBOMModify = false;
                boolean opinionFlag = false;
                int drawCount = 0;
                int bomCount = 0;
                if (CollectionUtils.isNotEmpty(subform47946)) {
                    for (int i = 0; i < subform47946.size(); i++) {
                        String beforeNo = subform47946.getJSONObject(i).getString("input91754");
                        String afterNo = subform47946.getJSONObject(i).getString("radio70670");
                        if (StringUtils.isNotBlank(beforeNo) && StringUtils.isNotBlank(afterNo)) {
                            String newBeforeNo = beforeNo.substring(0, 11);
                            String newAfterNo = afterNo.substring(0, 11);
                            if (newBeforeNo.equals(newAfterNo)) {
                                drawCount++;
                            } else {
                                bomCount++;
                            }
                        } else if (StringUtils.isBlank(beforeNo) && StringUtils.isNotBlank(afterNo)) {
                            bomCount++;
                        } else if (StringUtils.isNotBlank(beforeNo) && StringUtils.isBlank(afterNo)) {
                            bomCount++;
                        }
                    }
                }
                if (subform47946.size() > 0) {
                    if (drawCount > 0) {
                        isDrawModify = true;
                    } else {
                        isBOMModify = true;
                    }
                }
                JSONArray subform44512 = json.getJSONArray("subform44512");
                int count = 0;
                if (CollectionUtils.isNotEmpty(subform44512)) {
                    for (int i = 0; i < subform44512.size(); i++) {
                        String yesOrNo = subform44512.getJSONObject(i).getString("radio28579");
                        if ("是".equals(yesOrNo)) {
                            count++;
                        }
                    }
                }
                if (subform44512.size() > 0) {
                    if (count > 0) {
                        if (subform44512.size() == count) {
                            if (isDrawModify) {
                                execution.setVariable("DESIGN", true);
                            } else {
                                execution.setVariable("ORDER", true);
                            }
                        } else {
                            execution.setVariable("ORDER", true);
                        }
                    } else {
                        execution.setVariable("STOP", true);
                    }
                } else {
                    execution.setVariable("STOP", true);
                }
            }
        }
    }

    public String covrentCondition(String branchName, String condition, List<String> createDepartMent, int moldCost, JSONArray factorys) {
        boolean deptFlag = false;
        boolean factoryFlag = false;
        boolean costFlag = false;
        boolean deptConditionFlag = false;
        boolean factoryConditionFlag = false;
        boolean costConditionFlag = false;
        if (StringUtils.isNotBlank(condition)) {
            if (condition.contains("&&")) {
                String[] conditionArr1 = condition.split("&&");
                for (int i = 0; i < conditionArr1.length; i++) {
                    String condition2 = conditionArr1[i];
                    if (condition2.contains("department")) {
                        deptConditionFlag = true;
                        if (condition2.contains("=")) {
                            String department = condition2.split("=")[1];
                            if (department.contains("\\|\\|")) {
                                int count = 0;
                                String[] departmentArr = department.split("\\|\\|");
                                for (int j = 0; j < departmentArr.length; j++) {
                                    String department2 = departmentArr[j];
                                    if (createDepartMent.contains(department2)) {
                                        count++;
                                    }
                                }
                                if (count == departmentArr.length) {
                                    deptFlag = true;
                                }
                            } else {
                                String department2 = department;
                                if (createDepartMent.contains(department2)) {
                                    deptFlag = true;
                                }
                            }
                        } else if (condition2.contains("!=")) {
                            String department2 = condition2.split("!=")[1];
                            if (!createDepartMent.contains(department2)) {
                                deptFlag = true;
                            }
                        }
                    } else if (condition2.contains("moldCost")) {
                        costConditionFlag = true;
                        if (condition2.contains("&&")) {
                            boolean tempFlag1 = false;
                            boolean tempFlag2 = false;
                            String[] condition3 = condition2.split("&&");
                            for (int j = 0; j < condition3.length; j++) {
                                String condition4 = condition3[j];
                                if (condition4.contains(">")) {
                                    String moldCost2 = condition4.split(">")[1];
                                    int cost = Integer.parseInt(moldCost2);
                                    if (moldCost > cost) {
                                        tempFlag1 = true;
                                    }
                                } else if (condition4.contains("<")) {
                                    String moldCost2 = condition4.split("<")[1];
                                    int cost = Integer.parseInt(moldCost2);
                                    if (moldCost < cost) {
                                        tempFlag2 = true;
                                    }
                                }
                            }
                            if (tempFlag1 && tempFlag2) {
                                costFlag = true;
                            }
                        } else if (condition2.contains(">=")) {
                            String moldCost2 = condition2.split(">=")[1];
                            int cost = Integer.parseInt(moldCost2);
                            if (moldCost >= cost) {
                                costFlag = true;
                            }
                        } else if (condition2.contains("<=")) {
                            String moldCost2 = condition2.split("<=")[1];
                            int cost = Integer.parseInt(moldCost2);
                            if (moldCost <= cost) {
                                costFlag = true;
                            }
                        } else if (condition2.contains(">")) {
                            String moldCost2 = condition2.split(">")[1];
                            int cost = Integer.parseInt(moldCost2);
                            if (moldCost > cost) {
                                costFlag = true;
                            }
                        } else if (condition2.contains("<")) {
                            String moldCost2 = condition2.split("<")[1];
                            int cost = Integer.parseInt(moldCost2);
                            if (moldCost < cost) {
                                costFlag = true;
                            }
                        }

                    } else if (condition2.contains("factory")) {
                        factoryConditionFlag = true;
                        if (condition2.contains("=")) {
                            int count = 0;
                            String factory = condition2.split("=")[1];
                            if (factory.contains("\\|\\|")) {
                                String[] factoryArr = factory.split("\\|\\|");
                                for (int j = 0; j < factoryArr.length; j++) {
                                    String factory2 = factoryArr[j];
                                    if (factorys.contains(factory2)) {
                                        count++;
                                    }
                                }
                                if (count == factoryArr.length) {
                                    factoryFlag = true;
                                }
                            } else {
                                String factory2 = factory;
                                if (factorys.contains(factory2)) {
                                    factoryFlag = true;
                                }
                            }
                        }
                    }
                }
            } else {
                if (condition.contains("department")) {
                    deptConditionFlag = true;
                    if (condition.contains("=")) {
                        String department = condition.split("=")[1];
                        if (department.contains("\\|\\|")) {
                            int count = 0;
                            String[] departmentArr = department.split("\\|\\|");
                            for (int j = 0; j < departmentArr.length; j++) {
                                String department2 = departmentArr[j];
                                if (createDepartMent.contains(department2)) {
                                    count++;
                                }
                            }
                            if (count == departmentArr.length) {
                                deptFlag = true;
                            }
                        } else {
                            String department2 = department;
                            if (createDepartMent.contains(department2)) {
                                deptFlag = true;
                            }
                        }
                    } else if (condition.contains("!=")) {
                        String department2 = condition.split("!=")[1];
                        if (!createDepartMent.contains(department2)) {
                            deptFlag = true;
                        }
                    }
                } else if (condition.contains("moldCost")) {
                    costConditionFlag = true;
                    if (condition.contains("&&")) {
                        boolean tempFlag1 = false;
                        boolean tempFlag2 = false;
                        String[] condition3 = condition.split("&&");
                        for (int j = 0; j < condition3.length; j++) {
                            String condition4 = condition3[j];
                            if (condition4.contains(">")) {
                                String moldCost2 = condition4.split(">")[1];
                                int cost = Integer.parseInt(moldCost2);
                                if (moldCost > cost) {
                                    tempFlag1 = true;
                                }
                            } else if (condition4.contains("<")) {
                                String moldCost2 = condition4.split("<")[1];
                                int cost = Integer.parseInt(moldCost2);
                                if (moldCost < cost) {
                                    tempFlag2 = true;
                                }
                            }
                        }
                        if (tempFlag1 && tempFlag2) {
                            costFlag = true;
                        }
                    } else if (condition.contains(">=")) {
                        String moldCost2 = condition.split(">=")[1];
                        int cost = Integer.parseInt(moldCost2);
                        if (moldCost >= cost) {
                            costFlag = true;
                        }
                    } else if (condition.contains("<=")) {
                        String moldCost2 = condition.split("<=")[1];
                        int cost = Integer.parseInt(moldCost2);
                        if (moldCost <= cost) {
                            costFlag = true;
                        }
                    } else if (condition.contains(">")) {
                        String moldCost2 = condition.split(">")[1];
                        int cost = Integer.parseInt(moldCost2);
                        if (moldCost > cost) {
                            costFlag = true;
                        }
                    } else if (condition.contains("<")) {
                        String moldCost2 = condition.split("<")[1];
                        int cost = Integer.parseInt(moldCost2);
                        if (moldCost < cost) {
                            costFlag = true;
                        }
                    }
                } else if (condition.contains("factory")) {
                    factoryConditionFlag = true;
                    if (condition.contains("=")) {
                        String factory = condition.split("=")[1];
                        if (factory.contains("\\|\\|")) {
                            int count = 0;
                            String[] factoryArr = factory.split("\\|\\|");
                            for (int j = 0; j < factoryArr.length; j++) {
                                String factory2 = factoryArr[j];
                                if (factorys.contains(factory2)) {
                                    count++;
                                }
                            }
                            if (count == factoryArr.length) {
                                factoryFlag = true;
                            }
                        } else {
                            String factory2 = factory;
                            if (factorys.contains(factory2)) {
                                factoryFlag = true;
                            }
                        }
                    }
                }
            }
        }
        if (((deptFlag && deptConditionFlag) || (!deptFlag && !deptConditionFlag)) && ((factoryFlag && factoryConditionFlag) || (!factoryFlag && !factoryConditionFlag)) && ((costFlag && costConditionFlag) || (!costFlag && !costConditionFlag))) {
//            branchName=covertBranchName(branchName);
            return branchName;
        }
        return "";
    }

    private String covertBranchName(String branchName) {
        if (branchName.equals("Activity_07ecv1g")) {
            //审核(部门长)
            branchName = "A";
        } else if (branchName.equals("Activity_04uwa3o")) {
            //核定(部门长)
            branchName = "B";
        } else if (branchName.equals("Activity_0y1c8ka")) {
            //审核(部门长)
            branchName = "C";
        } else if (branchName.equals("Activity_0ty03k1")) {
            branchName = "D";
        } else if (branchName.equals("Activity_0nma1px")) {
            branchName = "E";
        } else if (branchName.equals("Activity_1mugmk0")) {
            branchName = "F";
        } else if (branchName.equals("Activity_02k3g4c")) {
            branchName = "G";
        } else if (branchName.equals("Activity_1fprof5")) {
            branchName = "H";
        } else if (branchName.equals("Activity_0pmwn7x")) {
            branchName = "I";
        } else if (branchName.equals("Activity_0vjf7r7")) {
            branchName = "J";
        } else if (branchName.equals("Activity_01pn6z0")) {
            branchName = "K";
        } else if (branchName.equals("Activity_0pwtoen")) {
            branchName = "L";
        } else if (branchName.equals("Activity_10spqlw")) {
            branchName = "M";
        }
        return branchName;
    }

    private void setProcessObjectLife(String key, String lifeCycleCode, List<EntityLifeCycleDTO> entityLifeCycleList) {
        if (key.equals("Y")) {
            TyplmGeneralOperationDTO goDTO = new TyplmGeneralOperationDTO();
            List<JSONObject> currentObj = new ArrayList();
            for (EntityLifeCycleDTO entityLifeCycleDTO : entityLifeCycleList) {
                String otype = entityLifeCycleDTO.getOtype();
                BigInteger oid = entityLifeCycleDTO.getOid();
                if ("ty.inteplm.mpm.CTyMPMProcessPlan".equalsIgnoreCase(entityLifeCycleDTO.getOtype()) || "ty.inteplm.mpm.CTyMPMOperation".equalsIgnoreCase(entityLifeCycleDTO.getOtype())) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("otype", otype);
                    jsonObject.put("oid", oid);
                    currentObj.add(jsonObject);
                }
            }

            goDTO.setCurrentObj(currentObj);
            List<JSONObject> list = new ArrayList();
            if (CollUtil.isNotEmpty(currentObj)) {
                TyplmTechnologyWorkFlowService typlmTechnologyWorkFlowService = (TyplmTechnologyWorkFlowService) SpringUtil.getBean(TyplmTechnologyWorkFlowService.class);
                typlmTechnologyWorkFlowService.getAllObjWorkFlow(goDTO, list);
            }

            if (CollUtil.isNotEmpty(list)) {
                List<String> keyList = (List) entityLifeCycleList.stream().map((obj) -> obj.getOtype() + ":" + obj.getOid()).distinct().collect(Collectors.toList());

                for (JSONObject object : list) {
                    String otype = this.parseObjOtype(object.getString("otype"));
                    BigInteger oid = TyplmEntityBaseUtil.getOidByStr(object.getString("oid"), BigInteger.ZERO);
                    String jsonkey = otype + ":" + oid;
                    if (org.apache.commons.lang3.StringUtils.isNotBlank(otype) && !TyplmEntityBaseUtil.isEmptyOid(oid) && !keyList.contains(jsonkey)) {
                        EntityLifeCycleDTO entityLifeCycleDTO = new EntityLifeCycleDTO();
                        entityLifeCycleDTO.setOid(object.getBigInteger("oid"));
                        entityLifeCycleDTO.setOtype(this.parseObjOtype(object.getString("otype")));
                        entityLifeCycleDTO.setLifeCycleStageKey(lifeCycleCode);
                        entityLifeCycleList.add(entityLifeCycleDTO);
                        keyList.add(jsonkey);
                    }
                }
            }
        }
    }

    private String parseObjOtype(String type) {
        String result = "";
        if (org.apache.commons.lang3.StringUtils.isEmpty(type)) {
            return result;
        } else {
            String[] otype = type.split("\\|");
            result = otype[0];
            return result;
        }
    }

    /**
     * 批量更新模组信息
     *
     * @param workFlowContainerId
     */
    @Override
    public void batchModifyModule(String workFlowContainerId) {
        try {
            WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
            if (!Objects.isNull(workFlowContainerView) && (workFlowContainerView instanceof FlowChgFormView || workFlowContainerView instanceof FlowChangeRequestView)) {
                log.info("当前流程属于变更通告流程");
                //表单内容
                String formData = "";
                if (workFlowContainerView instanceof FlowChgFormView) {
                    FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                    //获取变更通告对象
                    ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
                    String changeNo = chgFormVO.getObjectNumber();
                    formData = chgFormVO.getFormData();
                    if (StringUtils.isNotBlank(formData)) {
                        JSONObject formDataJson = JSONObject.parseObject(formData);
                        JSONArray subform57714 = formDataJson.getJSONArray("subform57714");
                        if (CollectionUtils.isNotEmpty(subform57714)) {
                            //关联变更件替换说明
                            for (int i = 0; i < subform57714.size(); i++) {
                                String type = subform57714.getJSONObject(i).get("input70284").toString();
                                String beforeChangeNo = subform57714.getJSONObject(i).getString("input36063");
                                String afterChangeNo = subform57714.getJSONObject(i).getString("input37516");
                                if (type.equals("修改") || type.equals("替换")) {
                                    String beforeNumber = beforeChangeNo.substring(0, 5);
                                    String afterNumber = afterChangeNo.substring(0, 5);
                                    List<ClassificationDO> classificationDOS = typlmClassificationService.queryClassificationByName(afterNumber);
                                    List<RtChangeaffectModuleDO> moduleDOS = this.rtChangeaffectModuleMapper.queryByChangeNoAndPartNo(changeNo, beforeChangeNo);
                                    if (CollectionUtils.isNotEmpty(moduleDOS)) {
                                        //关联受影响的模组
                                        for (RtChangeaffectModuleDO moduleDO : moduleDOS) {
                                            String modulenumber = moduleDO.getModulenumber();
                                            String moduleid = moduleDO.getModuleid();
                                            String partNo = moduleDO.getPartnumber();
                                            if (partNo.equals(beforeChangeNo)) {
                                                if (CollectionUtils.isNotEmpty(classificationDOS)) {
                                                    ClassificationDO classificationDO = classificationDOS.get(0);
                                                    String description = classificationDO.getDescription();
                                                    String displayFullName = classificationDO.getDisplayFullName();
                                                    RtCfgMzDO rtCfgMzDO = rtCfgMzMapper.selectRtCfgMzByMODULEID(moduleid);
                                                    if (rtCfgMzDO != null) {
                                                        String content = rtCfgMzDO.getContent();
                                                        String partList = rtCfgMzDO.getPartslist();
                                                        content = content.replace(beforeNumber, afterNumber);
                                                        JSONArray jsonArray = JSON.parseArray(partList);
                                                        JSONArray jsonArray2 = new JSONArray();
                                                        for (int j = 0; j < jsonArray.size(); j++) {
                                                            JSONObject jsonObject = jsonArray.getJSONObject(j);
                                                            if (jsonObject.getString("code").equals(beforeNumber)) {
                                                                jsonObject.put("code", afterNumber);
                                                                jsonObject.put("displayName", displayFullName);
                                                                jsonObject.put("description", description);
                                                            }
                                                            jsonArray2.set(j, jsonObject);
                                                        }
                                                        rtCfgMzDO.setContent(content);
                                                        rtCfgMzDO.setPartslist(jsonArray2.toJSONString());
                                                        rtCfgMzMapper.updateRtCfgMz(rtCfgMzDO);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            log.error("批量更新模组信息异常：{}", e);
            throw RTErrorCodeEnum.UPDATE_MODULE_ERROR.getException(e.getMessage());
        }
    }

    /**
     * 将变更表单中的数据汇总保存变更总表
     *
     * @param workFlowContainerId
     * @throws Exception
     */
    @Override
    public void collectChangeTargetData(String workFlowContainerId) throws Exception {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && (workFlowContainerView instanceof FlowChgFormView || workFlowContainerView instanceof FlowChangeRequestView)) {
            log.info("当前流程属于变更通告流程");
            if (workFlowContainerView instanceof FlowChgFormView) {
                FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                //获取变更通告对象
                ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
                //表单内容
                String formData = chgFormVO.getFormData();
                String changeNo = chgFormVO.getObjectNumber();
                RtChangeTargetDataDO deleteData = new RtChangeTargetDataDO(changeNo, "", "", "", "", "", "");
                long index = rtChangeTargetDataMapper.count(deleteData);
                if (index > 0) {
                    rtChangeTargetDataMapper.deleteBy(deleteData);
                }
                //受影响的EBOM
                List<RtChangeaffectEbomDO> ebomDOS = this.rtChangeaffectEbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                //受影响的成品BOM
                List<RtChangeaffectFinishedbomDO> finishedbomDOS = this.rtChangeaffectFinishedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                //关联受影响的BOM
                List<RtChangeaffectAssociatedbomDO> associatedbomDOS = this.rtChangeaffectAssociatedbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                //受影响的图纸
                List<RtChangeaffectDrawingdocumentDO> drawingdocumentDOS = this.rtChangeaffectDrawingdocumentMapper.queryByChangeNoAndPartNo(changeNo, "");
                //受影响的MBOM
                List<RtChangeaffectMbomDO> mbomDOS = this.rtChangeaffectMbomMapper.queryByChangeNoAndPartNo(changeNo, "");
                //变更前对象
                List<ECObjDTO> entityList = new ArrayList<>();
                List<RtChangeTargetDataDO> targetDataDOS = new ArrayList<>();
                if (StringUtils.isNotBlank(formData)) {
                    JSONObject formDataJson = JSONObject.parseObject(formData);
                    JSONArray subform47946 = formDataJson.getJSONArray("subform47946");
                    JSONArray subform57714 = formDataJson.getJSONArray("subform57714");
                    if (CollectionUtils.isNotEmpty(subform47946)) {
                        //图纸更改
                        for (int i = 0; i < subform47946.size(); i++) {
                            String type = subform47946.getJSONObject(i).get("radio81926").toString();
                            String beforeChangeNo = subform47946.getJSONObject(i).getString("input67563");
                            String afterChangeNo = subform47946.getJSONObject(i).getString("radio73127");
                            if (StringUtils.isNotBlank(afterChangeNo) && afterChangeNo.contains(",")) {
                                afterChangeNo = afterChangeNo.split(",")[0];
                            }
                            String afterCount = subform47946.getJSONObject(i).getString("number103708");
                            if ("图号升级".equals(type)) {
                                if (CollectionUtils.isNotEmpty(drawingdocumentDOS)) {
                                    List<RtChangeaffectDrawingdocumentDO> newDrawingdocumentDOS = drawingdocumentDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectDrawingdocumentDO drawingdocumentDO : newDrawingdocumentDOS) {
                                        String oid = drawingdocumentDO.getObjectid();
                                        String objecttype = drawingdocumentDO.getObjecttype();
                                        String objectversion = drawingdocumentDO.getObjectversion();
                                        String objectnumber = drawingdocumentDO.getPartnumber();
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "图文档", type, "", beforeChangeNo, afterChangeNo, "");
                                        data.setBeforechgoid(oid);
                                        data.setBeforechgotype(objecttype);
                                        data.setBeforechgno(objectnumber);
                                        data.setBeforechgver(objectversion);
                                        DocDetails docDetail = typlmDocumentService.queryDocDetails(new BigInteger(oid), objecttype);
                                        data.setBeforeobjtype(docDetail.getTypeDefName());
                                        data.setAfterchgoid(oid);
                                        data.setAffectobj(objectnumber);
                                        data.setAffectobjtype(type);
                                        targetDataDOS.add(data);
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(ebomDOS)) {
                                    List<RtChangeaffectEbomDO> newEbomDOS = ebomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectEbomDO ebomDO : newEbomDOS) {
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(beforeChangeNo, "PatternCode", RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(afterChangeNo, "PatternCode", RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = ebomDO.getObjectid();
                                        String objecttype = ebomDO.getObjecttype();
                                        String objectversion = ebomDO.getObjectversion();
                                        String objectnumber = ebomDO.getFirstParent();
                                        String segmNum = ebomDO.getSegmentnumber();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "EBOM", type, partDetailsVO.getView(), beforeChangeNo, afterChangeNo, objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("图样代号");
                                        data.setBeforesegmnum(segmNum);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("图样代号");
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype(type);
                                        targetDataDOS.add(data);
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(finishedbomDOS)) {
                                    List<RtChangeaffectFinishedbomDO> newFinishedbomDOS = finishedbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectFinishedbomDO mbomDO : newFinishedbomDOS) {
                                        String materialCode = mbomDO.getMaterialcode();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newBeforeChangeNo = beforeChangeNo + "-" + colorCode;
                                        String newAfterChangeNo = afterChangeNo + "-" + colorCode;
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        String segmNum = mbomDO.getSegmentnumber();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), beforeChangeNo, afterChangeNo, objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("物料码");
                                        data.setBeforesegmnum(segmNum);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype(type);
                                        targetDataDOS.add(data);
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(mbomDOS)) {
                                    List<RtChangeaffectMbomDO> newMbomDOS = mbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectMbomDO mbomDO : newMbomDOS) {
                                        String materialCode = mbomDO.getMaterialcode();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newBeforeChangeNo = beforeChangeNo + "-" + colorCode;
                                        String newAfterChangeNo = afterChangeNo + "-" + colorCode;
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        String segmNum = mbomDO.getSegmentnumber();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), newBeforeChangeNo, newAfterChangeNo, objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("物料码");
                                        data.setBeforesegmnum(segmNum);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype("图样代号");
                                        targetDataDOS.add(data);
                                    }
                                }
                            } else if ("图纸升版".equals(type)) {
                                if (CollectionUtils.isNotEmpty(drawingdocumentDOS)) {
                                    List<RtChangeaffectDrawingdocumentDO> newDrawingdocumentDOS = drawingdocumentDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectDrawingdocumentDO drawingdocumentDO : newDrawingdocumentDOS) {
                                        String oid = drawingdocumentDO.getObjectid();
                                        String objecttype = drawingdocumentDO.getObjecttype();
                                        String objectversion = drawingdocumentDO.getObjectversion();
                                        String objectnumber = drawingdocumentDO.getPartnumber();
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "图文档", type, "", beforeChangeNo, afterChangeNo, "");
                                        data.setBeforechgoid(oid);
                                        data.setBeforechgotype(objecttype);
                                        data.setBeforechgno(objectnumber);
                                        data.setBeforechgver(objectversion);
                                        DocDetails docDetail = typlmDocumentService.queryDocDetails(new BigInteger(oid), objecttype);
                                        data.setBeforeobjtype(docDetail.getTypeDefName());
                                        data.setAfterchgoid(oid);
                                        data.setAffectobj(objectnumber);
                                        data.setAffectobjtype(type);
                                        targetDataDOS.add(data);
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(ebomDOS)) {
                                    List<RtChangeaffectEbomDO> newEbomDOS = ebomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectEbomDO ebomDO : newEbomDOS) {
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(beforeChangeNo, "PatternCode", RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(afterChangeNo, "PatternCode", RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = ebomDO.getObjectid();
                                        String objecttype = ebomDO.getObjecttype();
                                        String objectversion = ebomDO.getObjectversion();
                                        String objectnumber = ebomDO.getFirstParent();
                                        String segmNum = ebomDO.getSegmentnumber();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "EBOM", type, partDetailsVO.getView(), beforeChangeNo, afterChangeNo, objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("图样代号");
                                        data.setBeforesegmnum(segmNum);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("图样代号");
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype(type);
                                        targetDataDOS.add(data);
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(finishedbomDOS)) {
                                    List<RtChangeaffectFinishedbomDO> newFinishedbomDOS = finishedbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectFinishedbomDO mbomDO : newFinishedbomDOS) {
                                        String materialCode = mbomDO.getMaterialcode();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newBeforeChangeNo = beforeChangeNo + "-" + colorCode;
                                        String newAfterChangeNo = afterChangeNo + "-" + colorCode;
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        String segmNum = mbomDO.getSegmentnumber();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), beforeChangeNo, afterChangeNo, objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("物料码");
                                        data.setBeforesegmnum(segmNum);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype(type);
                                        targetDataDOS.add(data);
                                    }
                                }
                            }
                        }
                    }
                    if (CollectionUtils.isNotEmpty(subform57714)) {
                        //关联变更件替换说明
                        for (int i = 0; i < subform57714.size(); i++) {
                            String type = subform57714.getJSONObject(i).get("input70284").toString();
                            String beforeChangeNo = subform57714.getJSONObject(i).getString("input36063");
                            String afterChangeNo = subform57714.getJSONObject(i).getString("input37516");
                            String beforeCount = subform57714.getJSONObject(i).getString("input64759");
                            String afterCount = subform57714.getJSONObject(i).getString("input58662");
                            String beforeSegmNum = subform57714.getJSONObject(i).getString("input69053");// number104249
                            String afterSegmNum = subform57714.getJSONObject(i).getString("input59564");// number104249
                            String changeObjType = subform57714.getJSONObject(i).getString("input102173");// number104249

                            if (type.equals("增加")) {
                                if (CollectionUtils.isNotEmpty(associatedbomDOS)) {
                                    List<RtChangeaffectAssociatedbomDO> newAssociatedbomDOS = associatedbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectAssociatedbomDO mbomDO : newAssociatedbomDOS) {
                                        String materialCode = mbomDO.getMaterialCode();
                                        String bomType = mbomDO.getBomtype();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newAfterChangeNo = "";
                                        if ("EBOM号".equals(bomType)) {
                                            newAfterChangeNo = afterChangeNo;
                                        } else if ("成品BOM".equals(bomType)) {
                                            newAfterChangeNo = afterChangeNo + "-" + colorCode;
                                        }
//                                        JSONObject beforeMaterial =this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode",RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), "", newAfterChangeNo, objectnumber);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftersegmnum(afterSegmNum);
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(afterChangeNo);
                                        data.setAffectobjtype(changeObjType);
                                        targetDataDOS.add(data);
                                    }
                                }

                                if (CollectionUtils.isNotEmpty(mbomDOS)) {
                                    List<RtChangeaffectMbomDO> newMbomDOS = mbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectMbomDO mbomDO : newMbomDOS) {
                                        String materialCode = mbomDO.getMaterialcode();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newAfterChangeNo = afterChangeNo + "-" + colorCode;
//                                        JSONObject beforeMaterial =this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode",RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), "", newAfterChangeNo, objectnumber);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftersegmnum(afterSegmNum);
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(afterChangeNo);
                                        data.setAffectobjtype(changeObjType);
                                        targetDataDOS.add(data);
                                    }
                                }
                            } else if (type.equals("删除") || type.equals("移动")) {
                                if (CollectionUtils.isNotEmpty(associatedbomDOS)) {
                                    List<RtChangeaffectAssociatedbomDO> newAssociatedbomDOS = associatedbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectAssociatedbomDO mbomDO : newAssociatedbomDOS) {
                                        String materialCode = mbomDO.getMaterialCode();
                                        String bomType = mbomDO.getBomtype();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newBeforeChangeNo = "";
                                        if ("EBOM号".equals(bomType)) {
                                            newBeforeChangeNo = beforeChangeNo;
                                        } else if ("成品BOM".equals(bomType)) {
                                            newBeforeChangeNo = beforeChangeNo + "-" + colorCode;
                                        }
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
//                                        JSONObject afterMaterial =this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode",RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), newBeforeChangeNo, "", objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("物料码");
                                        data.setBeforesegmnum(beforeSegmNum);
                                        data.setBeforecount(beforeCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype(changeObjType);
                                        targetDataDOS.add(data);
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(mbomDOS)) {
                                    List<RtChangeaffectMbomDO> newMbomDOS = mbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectMbomDO mbomDO : newMbomDOS) {
                                        String materialCode = mbomDO.getMaterialcode();
                                        String factory = mbomDO.getFactory();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newAfterChangeNo = afterChangeNo + "-" + colorCode;
//                                        JSONObject beforeMaterial =this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode",RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", factory);
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), "", newAfterChangeNo, objectnumber);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftersegmnum(afterSegmNum);
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(afterChangeNo);
                                        data.setAffectobjtype(changeObjType);
                                        targetDataDOS.add(data);
                                    }
                                }
                            } else if (type.equals("修改") || type.equals("替换")) {
                                if (CollectionUtils.isNotEmpty(associatedbomDOS)) {
                                    List<RtChangeaffectAssociatedbomDO> newAssociatedbomDOS = associatedbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectAssociatedbomDO mbomDO : newAssociatedbomDOS) {
                                        String materialCode = mbomDO.getMaterialCode();
                                        String bomType = mbomDO.getBomtype();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newBeforeChangeNo = "";
                                        String newAfterChangeNo = "";
                                        if ("EBOM号".equals(bomType)) {
                                            newBeforeChangeNo = beforeChangeNo;
                                            newAfterChangeNo = afterChangeNo;
                                        } else if ("成品BOM".equals(bomType)) {
                                            newBeforeChangeNo = beforeChangeNo + "-" + colorCode;
                                            newAfterChangeNo = afterChangeNo + "-" + colorCode;
                                        }
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), newBeforeChangeNo, newAfterChangeNo, objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("物料码");
                                        data.setBeforesegmnum(beforeSegmNum);
                                        data.setBeforecount(beforeCount);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftersegmnum(afterSegmNum);
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype(changeObjType);
                                        targetDataDOS.add(data);
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(mbomDOS)) {
                                    List<RtChangeaffectMbomDO> newMbomDOS = mbomDOS.stream().filter(item -> beforeChangeNo.equals(item.getPartnumber())).collect(Collectors.toList());
                                    for (RtChangeaffectMbomDO mbomDO : newMbomDOS) {
                                        String materialCode = mbomDO.getMaterialcode();
                                        String colorCode = "";
                                        if ("H".equals(materialCode.charAt(5))) {
                                            colorCode = materialCode.split("-")[1];
                                        } else {
                                            colorCode = materialCode.split("-")[2];
                                        }
                                        String newBeforeChangeNo = beforeChangeNo + "-" + colorCode;
                                        String newAfterChangeNo = afterChangeNo + "-" + colorCode;
                                        JSONObject beforeMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newBeforeChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        JSONObject afterMaterial = this.rtChangeMapper.queryMaterialByCodeAndType(newAfterChangeNo, "MaterialCode", RTPlmConstant.VIEW_DESIGN);
                                        String beforeOid = beforeMaterial.getString("OID");
                                        String beforeOtype = beforeMaterial.getString("OTYPE");
                                        String beforeNumber = beforeMaterial.getString("PARTNUMBER");
                                        String beforeName = beforeMaterial.getString("NAME");
                                        String beforeVersion = beforeMaterial.getString("VERSION");
                                        String beforeIterationid = beforeMaterial.getString("ITERATIONID");
                                        String afterOid = afterMaterial.getString("OID");
                                        String afterOtype = afterMaterial.getString("OTYPE");
                                        String afterNumber = afterMaterial.getString("PARTNUMBER");
                                        String afterName = afterMaterial.getString("NAME");
                                        String afterVersion = afterMaterial.getString("VERSION");
                                        String afterIterationid = afterMaterial.getString("ITERATIONID");
                                        String oid = mbomDO.getObjectid();
                                        String objecttype = mbomDO.getObjecttype();
                                        String objectversion = mbomDO.getObjectversion();
                                        String objectnumber = mbomDO.getFirstParent();
                                        PartDetailsVO partDetailsVO = typlmPdmPartService.queryPartDetailsForCO(new BigInteger(oid), objecttype);
                                        RtChangeTargetDataDO data = new RtChangeTargetDataDO(changeNo, "成品BOM", type, partDetailsVO.getView(), newBeforeChangeNo, newAfterChangeNo, objectnumber);
                                        data.setBeforechgoid(beforeOid);
                                        data.setBeforechgotype(beforeOtype);
                                        data.setBeforechgno(beforeNumber);
                                        data.setBeforechgname(beforeName);
                                        data.setBeforechgver(beforeVersion + "." + beforeIterationid);
                                        data.setBeforeobjtype("物料码");
                                        data.setBeforesegmnum(beforeSegmNum);
                                        data.setBeforecount(beforeCount);
                                        data.setAfterchgoid(afterOid);
                                        data.setAfterchgotype(afterOtype);
                                        data.setAfterchgno(afterNumber);
                                        data.setAfterchgname(afterName);
                                        data.setAfterchgver(afterVersion + "." + afterIterationid);
                                        data.setAfterobjtype("物料码");
                                        data.setAftersegmnum(afterSegmNum);
                                        data.setAftercount(afterCount);
                                        data.setParentoid(oid);
                                        data.setParentotype(objecttype);
                                        data.setParentno(objectnumber);
                                        data.setParentname(partDetailsVO.getName());
                                        data.setParentver(objectversion);
                                        data.setParentobjtype(partDetailsVO.getTypeName());
                                        data.setAffectobj(beforeNumber);
                                        data.setAffectobjtype(changeObjType);
                                        targetDataDOS.add(data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    /**
     * 自动设置参与者
     *
     * @param workFlowContainerId
     */
    @Override
    public void autoSetParticipants(String workFlowContainerId, String conditionStr, DelegateExecution execution) {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if (!Objects.isNull(workFlowContainerView) && (workFlowContainerView instanceof FlowChgFormView || workFlowContainerView instanceof FlowChangeRequestView)) {
            log.info("当前流程属于变更通告流程");
            List<UserTaskDTO> userTaskList = workFlowContainerView.getUserTaskList();
            List<FlowTaskRecord> flowTaskRecordList = workFlowContainerView.getFlowTaskRecordList();
            if (workFlowContainerView instanceof FlowChgFormView) {
                FlowChgFormView flowChgFormView = (FlowChgFormView) workFlowContainerView;
                //获取变更通告对象
                ChgFormVO chgFormVO = flowChgFormView.getChgFormVO();
                //表单内容
                String formData = chgFormVO.getFormData();
                String changeNo = chgFormVO.getObjectNumber();
                if (changeNo.contains("RTTJST")) {
                    //设计变更通知
                    if (StringUtils.isNotBlank(conditionStr)) {
                        JSONArray jsonArray = JSONArray.parseArray(conditionStr);
                        for (int i = 0; i < jsonArray.size(); i++) {
                            JSONObject conditionJson = jsonArray.getJSONObject(i);
                            String task1 = conditionJson.getString("task1");
                            String task2 = conditionJson.getString("task2");
                            String roleName = conditionJson.getString("roleName");
                            if (StringUtils.isNotBlank(task1) && StringUtils.isNotBlank(task2)) {
                                UserTaskDTO userTaskDTO = setParticipants(flowTaskRecordList, userTaskList, task1, task2, roleName);
                            } else if (StringUtils.isBlank(task1) && StringUtils.isNotBlank(task2)) {
                                JSONObject formDataJson = JSONObject.parseObject(formData);
                                List<PdmUserDTO> userList = new ArrayList<>();
                                //会签（关联变更判定）
                                UserTaskDTO countersign = userTaskList.stream().filter(u -> u != null && u.getId() != null && u.getId().equals(task2)).findFirst().orElse(null);
                                JSONArray subform63964 = formDataJson.getJSONArray("subform63964");
                                if (CollectionUtils.isNotEmpty(subform63964)) {
                                    for (int j = 0; j < subform63964.size(); j++) {
                                        String enginner = subform63964.getJSONObject(j).get("input96010").toString();
                                        if (StringUtils.isNotBlank(enginner)) {
                                            if (enginner.contains("(")) {
                                                enginner = enginner.substring(0, enginner.indexOf("("));
                                            }
                                            UserDO userDO = typlmUserService.queryUserByName(enginner);
                                            FlowTaskRecord flowTaskRecord = flowTaskRecordList.stream().filter(f -> f.getTaskDefId() != null && f.getTaskDefId().equals(task2)).findFirst().orElse(null);
                                            // 检查 flowTaskRecord 是否为 null
                                            BigInteger operatorOid = flowTaskRecord != null ? flowTaskRecord.getOperatorOid() : null;
                                            if (!userDO.getOid().equals(operatorOid)) {
                                                PdmUserDTO pdmUserDTO = convertPdmUserDTO(userDO);
                                                userList.add(pdmUserDTO);
                                            }
                                        }
                                    }
                                }
                                if (CollectionUtils.isNotEmpty(userList)) {
                                    countersign.setUserList(userList);
                                }
                            }
                        }
                        typlmWorkFlowContainerViewService.update(workFlowContainerView);
                    }
                } else if (changeNo.contains("RTTJJG") || changeNo.contains("RTTJXM")) {
                    //订单更改通知单
                    if (StringUtils.isNotBlank(conditionStr)) {
                        JSONArray jsonArray = JSONArray.parseArray(conditionStr);
                        for (int i = 0; i < jsonArray.size(); i++) {
                            JSONObject conditionJson = jsonArray.getJSONObject(i);
                            String task1 = conditionJson.getString("task1");
                            String task2 = conditionJson.getString("task2");
                            String roleName = conditionJson.getString("roleName");
                            if (StringUtils.isNotBlank(task1) && StringUtils.isNotBlank(task2)) {
                                UserTaskDTO userTaskDTO = setParticipants(flowTaskRecordList, userTaskList, task1, task2, roleName);
                            }
                        }
                        typlmWorkFlowContainerViewService.update(workFlowContainerView);
                    }
                }
            } else if (workFlowContainerView instanceof FlowChangeRequestView) {
                FlowChangeRequestView flowChangeRequestView = (FlowChangeRequestView) workFlowContainerView;
                //获取变更请求对象
                ChgRequestDetailVO requestDetailVO = flowChangeRequestView.getChgRequestDetailVO();
                String typeName = requestDetailVO.getTypeDefName();
                if ("客户ECR".equals(typeName) || "CUSTOMER_ECR".equals(typeName)) {
                    if (StringUtils.isNotBlank(conditionStr)) {
                        JSONArray jsonArray = JSONArray.parseArray(conditionStr);
                        for (int i = 0; i < jsonArray.size(); i++) {
                            JSONObject conditionJson = jsonArray.getJSONObject(i);
                            String task1 = conditionJson.getString("task1");
                            String task2 = conditionJson.getString("task2");
                            String roleName = conditionJson.getString("roleName");
                            if (StringUtils.isNotBlank(task1) && StringUtils.isNotBlank(task2)) {
                                UserTaskDTO userTaskDTO = setParticipants(flowTaskRecordList, userTaskList, task1, task2, roleName);
                            } else if (StringUtils.isBlank(task1) && StringUtils.isNotBlank(task2)) {
                                //表单内容
                                FlowTaskRecord flowTaskRecord = flowTaskRecordList.stream().filter(f -> f.getTaskDefId() != null && f.getTaskDefId().equals(task2)).findFirst().orElse(null);
                                UserTaskDTO countersign = userTaskList.stream().filter(u -> u != null && u.getId() != null && u.getId().equals(task2)).findFirst().orElse(null);
                                String formData = requestDetailVO.getFormData();
                                JSONObject formDataJson = JSONObject.parseObject(formData);
                                JSONArray subform44512 = formDataJson.getJSONArray("subform44512");
                                List<PdmUserDTO> userList = new ArrayList<>();
                                if (CollectionUtils.isNotEmpty(subform44512)) {
                                    for (int j = 0; j < subform44512.size(); j++) {
                                        String enginner = subform44512.getJSONObject(j).get("selectuser17630").toString();
                                        if (StringUtils.isNotBlank(enginner)) {
                                            JSONObject enginnerJSON = JSONObject.parseObject(enginner);
                                            enginner = enginnerJSON.get("name").toString();
                                            UserDO userDO = typlmUserService.queryUserByName(enginner);
                                            // 检查 flowTaskRecord 是否为 null
                                            BigInteger operatorOid = flowTaskRecord != null ? flowTaskRecord.getOperatorOid() : null;
                                            if (!userDO.getOid().equals(operatorOid)) {
                                                PdmUserDTO pdmUserDTO = convertPdmUserDTO(userDO);
                                                userList.add(pdmUserDTO);
                                            }
                                        }
                                    }
                                    if (CollectionUtils.isNotEmpty(userList)) {
                                        countersign.setUserList(userList);
                                    }
                                }
                            }
                        }
                        typlmWorkFlowContainerViewService.update(workFlowContainerView);
                    }
                }
            }
        }
    }

    /**
     * 设置参与者
     *
     * @param flowTaskRecordList
     * @param userTaskList
     * @param task1
     * @param task2
     * @param roleName
     */
    public UserTaskDTO setParticipants(List<FlowTaskRecord> flowTaskRecordList, List<UserTaskDTO> userTaskList, String task1, String task2, String roleName) {
        UserTaskDTO userTaskDTO2 = null;
        if (StringUtils.isNotBlank(task1) && StringUtils.isNotBlank(task2)) {
            UserTaskDTO userTaskDTO1 = userTaskList.stream().filter(u -> u != null && u.getId() != null && u.getId().equals(task1)).findFirst().orElse(null);
            userTaskDTO2 = userTaskList.stream().filter(u -> u != null && u.getId() != null && u.getId().equals(task2)).findFirst().orElse(null);
            List<PdmUserDTO> users = userTaskDTO1.getUserList();
            if (CollectionUtils.isEmpty(users)) {
                return userTaskDTO2;
            }
            List<PdmUserDTO> userList = new ArrayList<>();
            FlowTaskRecord flowTaskRecord2 = flowTaskRecordList.stream().filter(f -> f.getTaskDefId() != null && f.getTaskDefId().equals(task2)).findFirst().orElse(null);
            BigInteger operatorOid = flowTaskRecord2 != null ? flowTaskRecord2.getOperatorOid() : null;
            for (PdmUserDTO userDTO : users) {
                String userOid = userDTO.getOid();
                UserDO userDO = cqrtplm.util.CommonUtil.getCurrentUserLeader(new BigInteger(userOid), roleName);
                if (userDO != null) {
                    if (!userDO.getOid().equals(operatorOid)) {
                        PdmUserDTO pdmUserDTO = convertPdmUserDTO(userDO);
                        userList.add(pdmUserDTO);
                    }
                }
            }
            if (CollectionUtils.isNotEmpty(userList)) {
                userTaskDTO2.setUserList(userList);
            }
        }
        return userTaskDTO2;
    }

    /**
     * BOM发布校验
     *
     * @param workFlowContainerId
     */
    @Override
    public void checkEbomRelease(String workFlowContainerId) {
        WorkFlowContainerView workFlowContainerView = typlmWorkFlowContainerService.getWorkFlowContainerDetailByPrimaryKey(new BigInteger(workFlowContainerId));
        if ((workFlowContainerView instanceof WorkFlowObjectPackage)) {
            log.info("当前流程属于普通流程");
            WorkFlowObjectPackage workFlowObjectPackage = (WorkFlowObjectPackage) workFlowContainerView;
            List<FlowObject> flowObjectList = workFlowObjectPackage.getFlowObjectList();
            if (CollUtil.isEmpty(flowObjectList)) {
                return;
            }
            List<FlowObject> newFlowObjectList = flowObjectList.stream().filter(flowObject -> TableTypeConstrant.TY_PART_OTYPE.equals(flowObject.getRefObjectOtype()) && "EBOM号".equals(flowObject.getType())).collect(Collectors.toList());
            StringBuffer msg = new StringBuffer();
            for (FlowObject flowObject : newFlowObjectList) {
                BigInteger parentOid = flowObject.getRefObjectOid();
                String parentNumber = flowObject.getObjectNumber();
                String parentName = flowObject.getName();
                List<PartBomTree> partBomTreeList = commonService.queryChildPartsNoIba(flowObject.getObjectNumber(), String.valueOf(flowObject.getRefObjectOid()), "Design", true, null, "N", true).getPartBomTreeList();
                StringBuffer statusMsg = new StringBuffer();
                StringBuffer ibaMsg = new StringBuffer();
                if (CollUtil.isNotEmpty(partBomTreeList)) {
                    for (PartBomTree partBomTree : partBomTreeList) {
                        HashSet<PartBomTree> child = partBomTree.getChildren();
                        if (CollUtil.isNotEmpty(child)) {
                            for (PartBomTree partBomTree1 : child) {
                                String masteredoid = partBomTree1.getMasteredoid();
                                String partNumber = partBomTree1.getObjectNumber();
                                String partName = partBomTree1.getName();
                                String lifecyclestagekey = partBomTree1.getLifecyclestagekey();
                                String lifecycleState = partBomTree1.getLifecycleState();
                                if (!lifecyclestagekey.equals("RELEASED")) {
                                    statusMsg.append(partNumber + "（" + partName + "）：未生效；");
                                }
                                List<PartUsageLink> linkDOS = rtChangeMapper.queryPartUsageLinkInfo(parentOid.toString(), masteredoid);
                                if (CollUtil.isNotEmpty(linkDOS)) {
                                    for (PartUsageLink linkDO : linkDOS) {
                                        String SegmNum = rtChangeMapper.queryIBAValueByOidAndOtype(linkDO.getOid().toString(), linkDO.getOtype(), "SegmNum");
                                        String ManufacturingAttr = rtChangeMapper.queryIBAValueByOidAndOtype(linkDO.getOid().toString(), linkDO.getOtype(), "ManufacturingAttr");
                                        if (StringUtils.isBlank(SegmNum)) {
                                            if (!ibaMsg.toString().contains(partNumber + "（" + partName + "）：")) {
                                                ibaMsg.append(partNumber + "（" + partName + "）：");
                                            }
                                            ibaMsg.append("未设置段号；");
                                        }
                                        if (StringUtils.isBlank(ManufacturingAttr)) {
                                            if (!ibaMsg.toString().contains(partNumber + "（" + partName + "）：")) {
                                                ibaMsg.append(partNumber + "（" + partName + "）：");
                                            }
                                            ibaMsg.append("未设置制造属性；");
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (StringUtils.isNotBlank(statusMsg.toString())) {
                    msg.append(parentNumber + "下的：" + statusMsg);
                }
                if (StringUtils.isNotBlank(ibaMsg.toString())) {
                    msg.append(parentNumber + "下的：" + ibaMsg);
                }
            }
            if (StringUtils.isNotBlank(msg.toString())) {
                throw RTErrorCodeEnum.CHECK_EBOM_ERROR.getException(msg.toString());
            }
        }
    }

    /**
     * SRM OA SAP查询成品码状态
     *
     * @param mbomCode
     * @return
     */
    @Override
    public Object getMBOMStatus(String mbomCode) {
        JSONObject productJson = rtChangeMapper.queryMaterialByCodeAndType(mbomCode, "ProductCode", RTPlmConstant.VIEW_DESIGN);
        if (productJson == null) {
            return "未查询到成品码";
        }
        String oid = productJson.getString("OID");
        String otype = productJson.getString("OTYPE");
        PartDetailsVO partDetailsVO = this.typlmPartService.queryPartDetails(new BigInteger(oid), otype);
        if (partDetailsVO == null) {
            return "未查询到成品码";
        }
        Map<String, List<String>> ibaMap = partDetailsVO.getIbaAttributeMap();
        String lifecycleStateKey = partDetailsVO.getLifecycleStateKey();
        String status = "";
        String lockerNo = "";
        String lockerName = "";
//      String lockTime="";
        Date lockDate = null;
        if (lifecycleStateKey.equals("RELEASED")) {
            RtChangeLockInfoDO rtChangeLockInfoDO = new RtChangeLockInfoDO();
            rtChangeLockInfoDO.setProductCode(mbomCode);
            //获取成品码全部锁定信息
            List<RtChangeLockInfoDO> allLockInfoList = rtChangeLockInfoMapper.queryInfoByDO(rtChangeLockInfoDO);
            rtChangeLockInfoDO.setIsLock("1");
            //获取成品码解锁信息
            List<RtChangeLockInfoDO> releasedLockInfoList = rtChangeLockInfoMapper.queryInfoByDO(rtChangeLockInfoDO);
            if (releasedLockInfoList.size() == allLockInfoList.size()) {
                status = "1";
            } else {
                //获取成品码锁定信息
                rtChangeLockInfoDO.setIsLock("2");
                List<RtChangeLockInfoDO> changeLockInfoDOS = rtChangeLockInfoMapper.queryInfoByDO(rtChangeLockInfoDO);
                if (CollectionUtil.isNotEmpty(changeLockInfoDOS)) {
                    status = "2";
                }
                //获取最新锁定信息
                RtChangeLockInfoDO lockInfoDO = rtChangeLockInfoMapper.getInfoByDO(rtChangeLockInfoDO);
                if (lockInfoDO != null) {
                    lockDate = lockInfoDO.getLockTime();
                    String userStr = lockInfoDO.getLocker();
                    lockerNo = userStr.substring(0, userStr.indexOf("("));
                    lockerName = userStr.substring(userStr.indexOf("(") + 1, userStr.indexOf(")"));
                }
            }
        } else {
            status = "0";
        }
        String devCode = "";
        List<String> VINCodeRuleList = ibaMap.get("VINCodeRule");//VIN码规则
        List<String> dlcpmList = ibaMap.get("00020");//动力成品码
        List<String> gzsmList = ibaMap.get("reform");//改制说明
        List<String> gcList = ibaMap.get("factory");//工厂
        List<String> devCodeList = ibaMap.get("devCode");//开发令
        List<String> khdmList = ibaMap.get("CustomerCode");//客户代码
        List<String> tyjsgnfyzList = ibaMap.get("AgreeCretiYear");//同意接受该年份认证
        List<String> sfxpList = ibaMap.get("NeedBatch");//是否小批
        List<String> xpslList = ibaMap.get("smallBatchQuantity");//小批数量
        List<String> sfyjList = ibaMap.get("ModelMachine");//是否样机
        List<String> zxqdlList = ibaMap.get("MOQ1");//最小起订大量
        List<String> sfbbList = ibaMap.get("HalfBOM");//是否半BOM
        List<String> cpytList = ibaMap.get("application");//产品用途
        List<String> xqbidList = ibaMap.get("00033");//需求表ID
        if (CollectionUtil.isNotEmpty(devCodeList)) {
            devCode = devCodeList.get(0);
        }
        String ControlTableType = "";
        if (devCode.startsWith("Z")) {
            List<JSONObject> parentPart = rtChangeMapper.queryParentPart(mbomCode, RTPlmConstant.VIEW_DESIGN);
            if (CollectionUtil.isNotEmpty(parentPart)) {
                ControlTableType = "机组动力";
            } else {
                ControlTableType = "单机动力";
            }
        } else {
            ControlTableType = "机组";
        }
        RtMbomCodeDO rtMbomCodeDO = new RtMbomCodeDO();
        rtMbomCodeDO.setMbomcode(mbomCode);
        rtMbomCodeDO.setStatus(status);
        rtMbomCodeDO.setLastmodifydate(lockDate);
        rtMbomCodeDO.setBominfo("");
        rtMbomCodeDO.setDevcode(devCode);
        rtMbomCodeDO.setZlbh("");
        rtMbomCodeDO.setZvmgz(VINCodeRuleList == null ? null : VINCodeRuleList.get(0));
        rtMbomCodeDO.setBzfs("");
        rtMbomCodeDO.setAgreeacceptrznf(tyjsgnfyzList == null ? null : tyjsgnfyzList.get(0));
        rtMbomCodeDO.setAltitude("");
        rtMbomCodeDO.setCarburetorFuelType("");
        rtMbomCodeDO.setClientcode(khdmList == null ? null : khdmList.get(0));
        rtMbomCodeDO.setClientmodel("");
        rtMbomCodeDO.setClientRecordType("");
        rtMbomCodeDO.setCompletiontime(null);
        rtMbomCodeDO.setDlfactory("");
        rtMbomCodeDO.setDemandObjectID(xqbidList == null ? null : xqbidList.get(0));
        rtMbomCodeDO.setDemandType("");
        rtMbomCodeDO.setSmallbatchamount(xpslList == null ? 0 : Integer.parseInt(xpslList.get(0)));
        rtMbomCodeDO.setEnvironmentalCharacteristics("");
        rtMbomCodeDO.setControlTableType(ControlTableType);
        rtMbomCodeDO.setFactory(gcList == null ? null : gcList.get(0));
        rtMbomCodeDO.setHt("");
        rtMbomCodeDO.setIdleStart("");
        rtMbomCodeDO.setHighSpeedStart("");
        rtMbomCodeDO.setIsneedsmallbatch(sfxpList == null ? false : sfxpList.get(0).equals("是"));
        rtMbomCodeDO.setIsprototype(sfyjList == null ? false : sfyjList.get(0).equals("是"));
        rtMbomCodeDO.setItemClzj("");
        rtMbomCodeDO.setItemSbzj("");
        rtMbomCodeDO.setLastmodifydate(null);
        rtMbomCodeDO.setLastmodifyusercode(lockerNo);
        rtMbomCodeDO.setLastmodifyusername(lockerName);
        rtMbomCodeDO.setMintrayload(zxqdlList == null ? 0 : Integer.parseInt(zxqdlList.get(0)));
        rtMbomCodeDO.setOrdSc("");
        rtMbomCodeDO.setProductmodel("");
        rtMbomCodeDO.setProducttype("");
        rtMbomCodeDO.setProdYt(cpytList == null ? null : cpytList.get(0));
        rtMbomCodeDO.setSms("");
        rtMbomCodeDO.setTraymode("");
        rtMbomCodeDO.setTerminalRequirements1("");
        rtMbomCodeDO.setTerminalRequirements2("");
        rtMbomCodeDO.setTerminalRequirements3("");
        rtMbomCodeDO.setThrottleCombination("");
        rtMbomCodeDO.setTecRmk("");
        rtMbomCodeDO.setZdlbom(dlcpmList == null ? null : dlcpmList.get(0));
        rtMbomCodeDO.setZjzbom("");
        rtMbomCodeDO.setZsfbbom(sfbbList == null ? null : sfbbList.get(0));
        rtMbomCodeDO.setZbbomsm("");
        rtMbomCodeDO.setZdj("");
        rtMbomCodeDO.setZgzsm(gzsmList == null ? null : gzsmList.get(0));
        rtMbomCodeDO.setZbhdsm("");
        rtMbomCodeDO.setZlbh("");
        rtMbomCodeDO.setZvmgz("");
        return rtMbomCodeDO;
    }

    /**
     * 物料选点流程更新BOM属性
     *
     * @param workFlowContainerId
     * @param conditionStr
     */
    @Override
    public void updatePartBomAttr(String workFlowContainerId, String conditionStr) {
        List<SaveObjIBADTO> objWithIbaList = new ArrayList<>();
        String eBOMNumber = "";
        TyAccountContext.setIgnoreAuth(true);
        JSONObject ebomJson = rtChangeMapper.queryMaterialByCodeAndType(eBOMNumber, "EBOM_NUM", RTPlmConstant.VIEW_DESIGN);
        if (ebomJson != null) {
            String oid = ebomJson.getString("OID");
            String otype = ebomJson.getString("OTYPE");
            PartBomTreeByFilterVO bomTreeByFilterVO = this.commonService.queryChildParts(eBOMNumber, oid, "Design", Boolean.FALSE, null, "N", Boolean.FALSE);
            List<PartBomTree> list = bomTreeByFilterVO.getPartBomTreeList();
            for (PartBomTree partBomTree : list) {
                BigInteger usageLinkOid = partBomTree.getOid();
                String usageLinkOtype = partBomTree.getOtype();
                String partOid = partBomTree.getPartoid();
                String partOtype = partBomTree.getPartotype();
                String numberPath = partBomTree.getNumberPath();
                String[] numberPaths = numberPath.split("\\/");
                String parentNo = numberPaths[0];
                String childNo = numberPaths[1];
                updateIbaAttr(new BigInteger(partOid), partOtype, "FirstSuppliers", "", objWithIbaList);
                updateIbaAttr(usageLinkOid, usageLinkOtype, "ManufacturingAttr", "", objWithIbaList);
            }
            //物料属性 第一供应商 FirstSuppliers
            //Bom属性 制造属性 ManufacturingAttr
            if (CollUtil.isNotEmpty(objWithIbaList)) {
                typlmAttributeValueService.batchSaveIBAByObjsNoConstraint(objWithIbaList, false);
            }
        }
        TyAccountContext.setIgnoreAuth(false);
    }

    //设置IBA属性
    private void updateIbaAttr(BigInteger oid, String otype, String ibaKey, String ibaValue, List<SaveObjIBADTO> objWithIbaList) {
        IbaDTO ibaDTO = new IbaDTO();
        ibaDTO.setKey(ibaKey);
        ibaDTO.setValue(ibaValue);
        List<IbaDTO> ibaDTOList = new ArrayList<>();
        ibaDTOList.add(ibaDTO);
        SaveObjIBADTO saveObjIBADTO = new SaveObjIBADTO();
        saveObjIBADTO.setObjIbaList(ibaDTOList);
        saveObjIBADTO.setCTyEntityBaseDO(new CTyEntityBaseDO(oid, otype));
        objWithIbaList.add(saveObjIBADTO);
    }

    public void setEcaRelevanceChgAfterObjectSpecifyState(BigInteger ecaId, String targetLifeCycleStateKey) {
        List<ChgActRelDataLinkDO> recordLinkDOS = this.typlmChgActRelDataLinkService.queryObjOidAndOtypeByECAId(ecaId);
        if (!CollUtil.isEmpty(recordLinkDOS)) {
            Map<String, List<ChgActRelDataLinkDO>> map = (Map) recordLinkDOS.stream().collect(Collectors.groupingBy(ChgActRelDataLinkDO::getBotype));
            List<CTyEntityBaseDO> updateList = new ArrayList();

            for (Map.Entry<String, List<ChgActRelDataLinkDO>> entry : map.entrySet()) {
                String otype = (String) entry.getKey();
                List<ChgActRelDataLinkDO> chgActRelDataLinkDOList = (List) entry.getValue();
                if (!CollUtil.isEmpty(chgActRelDataLinkDOList)) {
                    List<BigInteger> oidList = (List) chgActRelDataLinkDOList.stream().map(ChgActRelDataLinkDO::getBoid).collect(Collectors.toList());
                    List<CTyEntityBaseDO> entitys = CommonUtil.getEntityListIgnoreNotExistForEach(oidList, otype);
                    TyplmLoggerUtil.debug(log, () -> "获取的变更后对象为==>【{}】", () -> new Object[]{JSON.toJSONString(entitys)});
                    boolean isUpdateSubMpm = this.tymMpmWorkFlowAdaptationService.isUpdateAllMpm();

                    for (CTyEntityBaseDO entity : entitys) {
                        if (entity instanceof ITyLifeCycleManaged) {
                            if (entity instanceof ITyIterated && ((ITyIterated) entity).getIslastiterated() != 1L) {
                                ITyIterated iTyIterated = (ITyIterated) entity;
                                BigInteger branchid = iTyIterated.getBranchid();
                                List<CTyEntityBaseDO> entityByBranchId = CommonUtil.getEntityByBranchId(entity.getOtype(), Arrays.asList(branchid.toString()));
                                entity = (CTyEntityBaseDO) entityByBranchId.stream().filter((item) -> Long.valueOf(1L).equals(((ITyIterated) item).getIslastiterated())).findFirst().orElse(null);
                                if (entity == null) {
                                    continue;
                                }
                            }

                            ITyLifeCycleManaged iTyLifeCycleManaged = (ITyLifeCycleManaged) entity;
                            boolean b = this.checkLifeCycleState(iTyLifeCycleManaged.getLifecyclestagekey(), targetLifeCycleStateKey, iTyLifeCycleManaged.getLifecycletemplateoid());
                            if (b) {
                                if (isUpdateSubMpm && (entity.getOtype().equals("ty.inteplm.mpm.CTyMPMProcessPlan") || entity.getOtype().equals("ty.inteplm.mpm.CTyMPMOperation"))) {
                                    List<IdentifierEntity> subMpmEntities = this.tymMpmWorkFlowAdaptationService.getAllObjWorkFlow(new IdentifierEntity(entity.getOid(), entity.getOtype()));
                                    if (!org.springframework.util.CollectionUtils.isEmpty(subMpmEntities)) {
                                        updateList.addAll(CommonUtil.getEntityListIgnoreNotExist(subMpmEntities));
                                    }
                                }

                                updateList.add(entity);
                            }
                        }
                    }
                }
            }
            if (!org.springframework.util.CollectionUtils.isEmpty(updateList)) {
                this.typlmCommonLifecycleService.batchUpdateEntityLifecycle(updateList, targetLifeCycleStateKey, true, true);
            }

        }
    }

    private boolean checkLifeCycleState(String sourceLifeCycleStateKey, String targetLifeCycleStateKey, BigInteger lifecycletemplateoid) {
        TyplmLoggerUtil.debug(log, () -> "生命周期状态校验的入参为==>sourceLifeCycleStateKey = 【{}】，targetLifeCycleStateKey = 【{}】，lifecycletemplateoid = 【{}】", () -> new Object[]{sourceLifeCycleStateKey, targetLifeCycleStateKey, lifecycletemplateoid});
        if (sourceLifeCycleStateKey.equalsIgnoreCase(targetLifeCycleStateKey)) {
            return false;
        } else {
            TyLifecycleTemplateAllVO tyLifecycleTemplateAllVO = this.typlmLifecycleTemplateService.queryLifecycleTemplateByOid(lifecycletemplateoid);
            TyplmLoggerUtil.debug(log, () -> "获取的生命周期模板为==>【{}】", () -> new Object[]{JSON.toJSONString(tyLifecycleTemplateAllVO)});
            if (org.springframework.util.ObjectUtils.isEmpty(tyLifecycleTemplateAllVO)) {
                throw SystemErrorCodeEnum.LIFECYCLE_TEMPLATE_NOT_EXIST.getException(new Object[0]);
            } else {
                TyLifecycleTemplateAndStatusDTO lifeCycleStageTemplateByTemplate = this.typlmLifecycleTemplateService.getLifeCycleStageTemplateByTemplate((String) null, tyLifecycleTemplateAllVO.getMastername());
                TyplmLoggerUtil.debug(log, () -> "获取生命周期模板下的生命周期阶段为==>【{}】", () -> new Object[]{JSON.toJSONString(lifeCycleStageTemplateByTemplate)});
                if (!org.springframework.util.ObjectUtils.isEmpty(lifeCycleStageTemplateByTemplate) && !CollUtil.isEmpty(lifeCycleStageTemplateByTemplate.getLifecycleState())) {
                    List<TyLifecycleStateDTO> lifecycleState = lifeCycleStageTemplateByTemplate.getLifecycleState();
                    List<String> stageKey = (List) lifecycleState.stream().map(TyLifecycleStateDTO::getCode).collect(Collectors.toList());
                    if (!stageKey.contains(targetLifeCycleStateKey)) {
                        log.info(SystemErrorCodeEnum.NOT_IN_THE_DEFINITION_OF_LIFECYCLE_TEMPLATE.getException(new Object[]{targetLifeCycleStateKey, tyLifecycleTemplateAllVO.getMastername()}).getMessage());
                        return false;
                    } else {
                        LifeCycleTemplateConvertQueryDTO lifeCycleTemplateConvertQueryDTO = new LifeCycleTemplateConvertQueryDTO();
                        lifeCycleTemplateConvertQueryDTO.setLifecycleStageKey(sourceLifeCycleStateKey);
                        lifeCycleTemplateConvertQueryDTO.setTemplateName(tyLifecycleTemplateAllVO.getMastername());
                        lifeCycleTemplateConvertQueryDTO.setOperationNameList(Collections.singletonList("SET_STATE"));
                        List<LifeCycleTemplateConvertDTO> lifeCycleTemplateConvertDTOList = this.typlmLifecycleTemplateService.batchGetTemplateNameConvertState(Lists.list(new LifeCycleTemplateConvertQueryDTO[]{lifeCycleTemplateConvertQueryDTO}));
                        List<String> convertCodeList = ((LifeCycleTemplateConvertDTO) lifeCycleTemplateConvertDTOList.get(0)).getConvertCodeList();
                        if (!convertCodeList.contains(targetLifeCycleStateKey)) {
                            log.info(SystemErrorCodeEnum.NOT_IN_TRANSFORMABLE_STATE.getException(new Object[]{targetLifeCycleStateKey, tyLifecycleTemplateAllVO.getMastername()}).getMessage());
                            return false;
                        } else {
                            return true;
                        }
                    }
                } else {
                    throw SystemErrorCodeEnum.NO_STATE_DEFINITION.getException(new Object[]{tyLifecycleTemplateAllVO.getMastername()});
                }
            }
        }
    }

    /**
     * 获取属性
     *
     * @param modultitemsubVOS
     * @param json
     * @param materialCode
     * @return
     */

    private List<DspfStatusModultitemsubVO> getAttributeValue(List<DspfStatusModultitemsubVO> modultitemsubVOS, JSONObject json, String materialCode) {
        String descrCode = json.getString("descrCode");
        JSONObject partJSON = this.rtChangeMapper.queryLatestMaterialByCode(materialCode, RTPlmConstant.VIEW_DESIGN);
        if (partJSON != null) {
            String oid = partJSON.getString("OID");
            String otype = partJSON.getString("OTYPE");
            String attrValue = this.rtChangeMapper.queryIBAValueByOidAndOtype(oid, otype, descrCode);
            DspfStatusModultitemsubVO modultitemsubVO = new DspfStatusModultitemsubVO();
            modultitemsubVO.setDescrCode(descrCode);
            modultitemsubVO.setDescrName(attrValue);
            modultitemsubVOS.add(modultitemsubVO);
        }
        return modultitemsubVOS;
    }

    /**
     * 批量修改指定
     *
     * @param appiontList
     */
    private String appointBatchUpdate(List<JSONObject> appiontList) {
        StringBuffer errbuffer = new StringBuffer();
        if (CollectionUtils.isNotEmpty(appiontList)) {
            for (JSONObject tempJson : appiontList) {
                String type = tempJson.getString("type");
                String beforeChangeNo = tempJson.getString("beforeChangeNo");
                String afterChangeNo = tempJson.getString("afterChangeNo");
                String customer = tempJson.getString("customer");
                String DevelopmentOrder = tempJson.getString("DevelopmentOrder");
                String factory = tempJson.getString("factory");
                String productCode = tempJson.getString("productCode");
                String hasSendSAP = tempJson.getString("hasSendSAP");
                if (StringUtils.isBlank(beforeChangeNo) || StringUtils.isBlank(DevelopmentOrder) || StringUtils.isBlank(customer) || StringUtils.isBlank(factory))
                    continue;
                List<String> factorys = Arrays.asList(factory.split(","));
                for (String factoryStr : factorys) {
                    List<RtZdDbDO> dbDOS = this.rtZdMapper.selectDbByPartAndDevAndCusAndFactory(beforeChangeNo, DevelopmentOrder, customer, factoryStr);
                    if (CollectionUtils.isNotEmpty(dbDOS)) {
                        if ("图号升级".equals(type)) {
                            //继承指定
                            for (RtZdDbDO dbDO : dbDOS) {
                                UUID uuid = UUID.randomUUID();
                                dbDO.setAid(uuid.toString());
                                dbDO.setMaterialCode(afterChangeNo);
                                this.rtZdMapper.insertDb(dbDO);
                            }
                        } else if ("替换".equals(type) || "修改".equals(type)) {
                            if (StringUtils.isBlank(hasSendSAP) || "否".equals(hasSendSAP)) {
                                //变更后物料未下发SAP，为新物料，继承变更前指定
                                for (RtZdDbDO dbDO : dbDOS) {
                                    UUID uuid = UUID.randomUUID();
                                    dbDO.setAid(uuid.toString());
                                    dbDO.setMaterialCode(afterChangeNo);
                                    this.rtZdMapper.insertDb(dbDO);
                                }
                            } else if ("是".equals(hasSendSAP)) {
                                //变更后物料已下发SAP
                                List<RtZdDbDO> dbDOS2 = this.rtZdMapper.selectDbByPartAndDevAndCusAndFactory(afterChangeNo, DevelopmentOrder, customer, factoryStr);
                                if (CollectionUtils.isEmpty(dbDOS2)) {
                                    //变更后物料无指定，查询变更后物料是否有货源
                                    int i = 0;
                                    for (RtZdDbDO dbDO : dbDOS) {
                                        String supplier = dbDO.getAppointSupplier();
                                        //根据物料码、工厂、供应商判断变更前指定与变更后货源是否有交集
                                        String body = converSoureListInputAttr(afterChangeNo, factoryStr, supplier);
                                        String sourceStr = this.commonService.sendPostRequest(sapSourceListUrl, sapSourceListUsername, sapSourceListPassword, body);
                                        if (StringUtils.isNotBlank(sourceStr)) {
                                            JSONObject obj = JSON.parseObject(sourceStr);
                                            Object ET_TAB = obj.get("ET_TAB");
                                            if (ET_TAB != null && ET_TAB instanceof JSONObject) {
                                                JSONObject etTab = (JSONObject) ET_TAB;
                                                JSONArray items = (JSONArray) etTab.get("item");
                                                if (CollectionUtils.isEmpty(items)) {
                                                    i++;
                                                }
                                            } else {
                                                i++;
                                            }
                                        }
                                    }
                                    ;
                                    //判断变更前物料的指定与变更后物料的货源是否有交集
                                    if (i == dbDOS.size()) {
                                        //无交集则报错
                                        errbuffer.append("变更前物料" + beforeChangeNo + "的指定与变更后物料" + afterChangeNo + "的货源无交集；\r\n");
                                    } else {
                                        //有交集则继承变更前物料的指定
                                        if (CollectionUtils.isNotEmpty(dbDOS)) {
                                            for (RtZdDbDO dbDO : dbDOS) {
                                                UUID uuid = UUID.randomUUID();
                                                dbDO.setAid(uuid.toString());
                                                dbDO.setMaterialCode(afterChangeNo);
                                                this.rtZdMapper.insertDb(dbDO);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return errbuffer.toString();
    }


    private @NotNull ECAddChangeObjectDTO getEcAddChangeObjectDTO(List<ECObjDTO> ecObjDTOList, IdentifierEntity entity, List<ECObjData> ecnObjectList) {

        BigInteger baseObjectOid = entity.getOid();
        String baseObjectOtype = entity.getOtype();
        ECAddChangeObjectDTO addChangeObjectDTO = new ECAddChangeObjectDTO();
        addChangeObjectDTO.setEntity(new IdentifierEntity(baseObjectOid, baseObjectOtype));
        addChangeObjectDTO.setEntityList(ecObjDTOList);
        addChangeObjectDTO.setAllObjDTOList(ecnObjectList);
        List<ECObjDTO> oirAllObjList = new ArrayList<>();
        for (ECObjData item : ecnObjectList) {
            ECObjDTO ecObjData = new ECObjDTO();
            ecObjData.setOid(item.getOid());
            ecObjData.setOtype(item.getOtype());
            oirAllObjList.add(ecObjData);
        }
        addChangeObjectDTO.setOirAllObjList(oirAllObjList);
        return addChangeObjectDTO;
    }

    /**
     * 封装变更对象
     *
     * @param changeRequest
     * @return
     */
    private @NotNull IdentifierEntity getIdentifierEntity(ChgRequestDetailVO changeRequest) {
        IdentifierEntity identifierEntity = new IdentifierEntity();
        identifierEntity.setOid(changeRequest.getOid());
        identifierEntity.setOtype(changeRequest.getOtype());
        return identifierEntity;
    }

    private FlowChangeRequestView getFlowChangeRequestView(List<UserTaskDTO> userTaskList, WorkFlow workFlow, FlowChangeRequestView flowChgFormView, List<PdmUserDTO> userList) {
        FlowChangeRequestView flowChangeRequestView = new FlowChangeRequestView();
        ChgRequestDetailVO chgRequestDetailVO = flowChgFormView.getChgRequestDetailVO();
        flowChangeRequestView.setChgRequestDetailVO(chgRequestDetailVO);
        flowChangeRequestView.setOid(flowChgFormView.getOid());
        flowChangeRequestView.setCodeNumber("WT" + System.currentTimeMillis());
        flowChangeRequestView.setOtype(TableTypeConstrant.TY_WORKFLOWCONTAINER_OTYPE);
        flowChangeRequestView.setName(chgRequestDetailVO.getObjectNumber() + "," + chgRequestDetailVO.getName() + "_变更审批流程");

        flowChangeRequestView.setWorkFlowId(workFlow.getOid());
        flowChangeRequestView.setWorkFlowName(workFlow.getName());
        flowChangeRequestView.setDeploymentId(workFlow.getDeploymentId());

        flowChangeRequestView.setUserTaskList(userTaskList);
        flowChangeRequestView.setEmergencyDegree("commonly");
        flowChangeRequestView.setContainerOid(flowChgFormView.getContainerOid());
        flowChangeRequestView.setContainerOtype(flowChgFormView.getContainerOtype());
        flowChangeRequestView.setBaseObjectOtype(flowChgFormView.getBaseObjectOtype());
        flowChangeRequestView.setBaseObjectOid(flowChgFormView.getBaseObjectOid());

        UserDO user = TyAccountContext.getUser();
        flowChangeRequestView.setCreatorOid(user.getOid());
        flowChangeRequestView.setCreatorOtype(TableTypeConstrant.TY_USER_OTYPE);
        flowChangeRequestView.setUpdaterOid(user.getOid());
        flowChangeRequestView.setUpdaterOtype(TableTypeConstrant.TY_USER_OTYPE);

        flowChangeRequestView.setManagerList(userList);

        IdentifierEntity identifierEntity = new IdentifierEntity();
        identifierEntity.setOid(flowChgFormView.getOid());
        identifierEntity.setOtype(flowChgFormView.getOtype());
        flowChangeRequestView.setIdentifierRef(identifierEntity);
        return flowChangeRequestView;
    }

    /**
     * 获取流程中每个任务节点详细信息，并设置节点参与者
     *
     * @return
     */
    public @NotNull List<UserTaskDTO> getUserTaskDTOS(WorkFlow workFlow, List<PdmUserDTO> userList, BigInteger containerOid, String containerOtype) {
        List<UserTaskDTO> userTaskList = typlmWorkFlowContainerService.getAllUserTask(workFlow.getOid(), containerOid, containerOtype);
        //遍历设置流程节点的参与者
        if (CollUtil.isNotEmpty(userList)) {
            UserTaskDTO userTaskDTO = userTaskList.get(0);
            userTaskDTO.setUserList(userList);
        }
        return userTaskList;
    }

    /**
     * 获取List<PdmUserDTO> 参与者信息
     *
     * @param userNameList
     * @return
     */
    public List<PdmUserDTO> getPdmUserDTOS(List<String> userNameList) {
        List<UserDO> userDOS = this.typlmUserService.queryUserByNameList(userNameList);
        List<PdmUserDTO> pdmUserDTOList = new ArrayList<>();
        if (CollUtil.isNotEmpty(userDOS)) {
            pdmUserDTOList = convertToPdmUserDTO(userDOS);
        }
        return pdmUserDTOList;
    }

    public WorkFlow getDefaultWorkFlow(String templateName) {
        Example example = new Example(WorkFlow.class, true, true);
        example.createCriteria().andEqualTo("name", templateName);
        List<WorkFlow> workFlowList = this.typlmWorkFlowService.simpleQueryListByExample(example);
        if (ObjectUtils.isEmpty(workFlowList)) {
            //            throw new Exception("");
        }
        return workFlowList.get(0);
    }

    public List<PdmUserDTO> convertToPdmUserDTO(List<UserDO> userDOList) {
        List<PdmUserDTO> userList = new ArrayList<>();
        if (CollUtil.isEmpty(userDOList)) {
            return userList;
        }
        for (UserDO userDO : userDOList) {
            PdmUserDTO pdmUserDTO = convertPdmUserDTO(userDO);
            userList.add(pdmUserDTO);
        }
        return userList;
    }

    private PdmUserDTO convertPdmUserDTO(UserDO userDO) {
        TyplmLoggerUtil.debug(log, () -> {
            return "convertPdmUserDTO 方法入参userDO ==> 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(userDO)};
        });
        PdmUserDTO pdmUserDTO = new PdmUserDTO();
        BeanUtils.copyProperties(userDO, pdmUserDTO);
        pdmUserDTO.setOid(userDO.getOid().toString());
        pdmUserDTO.setOtype(userDO.getOtype());
        pdmUserDTO.setAccount(userDO.getName());
        pdmUserDTO.setUsername(userDO.getFullname());
        TyplmLoggerUtil.debug(log, () -> {
            return "convertPdmUserDTO 返回值pdmUserDTO ==> 【{}】";
        }, () -> {
            return new Object[]{JSONObject.toJSONString(pdmUserDTO)};
        });
        return pdmUserDTO;
    }

    private List<ChgActivityVO> getEcaByEcnId(BigInteger ecnId) {
        TyplmLoggerUtil.debug(log, () -> "根据ecnId【{}】查询eca集合", () -> new Object[]{ecnId});
        ChgNoticeDO chgNoticeDO = this.typlmChgNoticeQueryService.selectByPrimaryKey(ecnId);
        if (Objects.isNull(chgNoticeDO)) {
            TyException.throwSingleTyExceptionVarargs(ResponseCodeEnum.BIZ_OBJECT_NOT_FOUND, new String[]{ecnId.toString()});
        }

        return this.typlmChangeLinkService.queryECAByECO(chgNoticeDO);
    }

    private List<ECObjDataVO> getChangeObjByEca(List<? extends ChgActivityDO> ecaList, Boolean before) {
        List<ECObjDataVO> result = new ArrayList<>();
        ecaList.forEach((item) -> result.addAll(this.typlmChangeObjectLinkService.queryECObjList(new IdentifierEntity(item.getOid(), "ty.inteplm.change.CTyChangeActivity"), before)));
        return result;
    }

    private List<ECObjDataVO> checkObjectCanChange(List<ECObjDataVO> ecaChangeBeforeObjects) {
        List<ECObjDataVO> result = new ArrayList();
        if (CollUtil.isEmpty(ecaChangeBeforeObjects)) {
            return result;
        } else {
            Map<String, List<ECObjDataVO>> typeListMap = (Map) ecaChangeBeforeObjects.stream().collect(Collectors.groupingBy(ECObjDataVO::getOtype));
            Map<String, List<BigInteger>> otypeToBranchIdListMap = new HashMap();

            for (Map.Entry<String, List<ECObjDataVO>> entry : typeListMap.entrySet()) {
                String type = (String) entry.getKey();
                List<ECObjDataVO> value = (List<ECObjDataVO>) entry.getValue();
                List<BigInteger> masteredList = (List<BigInteger>) value.stream().map(ECObjDataVO::getMasteredoid).distinct().collect(Collectors.toList());
                List<BasicObjectDTO> list = null;//this.typlmCommonIterateService.batchQueryObjLastVersionByMasterId(masteredList, type);

                if (CollectionUtils.isNotEmpty(list)) {
                    for (BasicObjectDTO objectDTO : list) {
                        List<BigInteger> branchids = (List) otypeToBranchIdListMap.computeIfAbsent(objectDTO.getOtype(), (k) -> new ArrayList());
                        branchids.add(objectDTO.getBranchid());
                    }
                }
            }

            if (CollUtil.isEmpty(otypeToBranchIdListMap)) {
                return ecaChangeBeforeObjects;
            } else {
                for (Map.Entry<String, List<ECObjDataVO>> entry : typeListMap.entrySet()) {
                    if (otypeToBranchIdListMap.containsKey(entry.getKey())) {
                        List<BigInteger> branchids = (List) otypeToBranchIdListMap.get(entry.getKey());
                        if (CollectionUtils.isNotEmpty(branchids)) {
                            for (ECObjDataVO ecObjDataVO : entry.getValue()) {
                                if (branchids.contains(ecObjDataVO.getBranchid())) {
                                    result.add(ecObjDataVO);
                                }
                            }
                        }
                    }
                }

                return result;
            }
        }
    }

    /**
     * @param identifierEntity 变更单
     * @param changeFromType   变更单类型
     * @return
     */
    private List<ECObjData> getAfterChangeObjList(IdentifierEntity identifierEntity, String changeFromType) {//
        List<ECCommonVO> xtRefObjList = this.typlmChangeRequestService.getEcLinkObjByIdentifierEntity(identifierEntity);
        List<ECObjData> ecnAfterChangeList = new ArrayList<>();
        List<ECCommonVO> filterEcnList = xtRefObjList.stream().filter(item -> changeFromType.equals(item.getLogicalidentifier())).collect(Collectors.toList());
        for (ECCommonVO commonVO : filterEcnList) {
            IdentifierEntity tyEntity = commonVO.getIdentifierRef();
            ChangeObjectDTO changeObjectDTO = new ChangeObjectDTO();
            changeObjectDTO.setEcIdentifier(tyEntity);
            List<ECObjData> ecnAfterObjs = this.typlmEngineeringChangeService.listChangeObjAfter(changeObjectDTO);
            ecnAfterChangeList.addAll(ecnAfterObjs);
        }
        return ecnAfterChangeList;
    }

    //转换为可挂接的变更后对象
    private List<ECObjDTO> convertBusinessObjToEcoObj(List<BusinessObjectVO> businessObjectVOS) {
        List<ECObjDTO> entityList = new ArrayList<>();
        for (BusinessObjectVO objectVO : businessObjectVOS) {
            ECObjDTO ecObjDTO = new ECObjDTO();
            ecObjDTO.setOtype(objectVO.getTypeDefName());
            ecObjDTO.setOid(objectVO.getId());
            entityList.add(ecObjDTO);
        }
        return entityList;
    }

    private List<BusinessObjectVO> getBusinessObjectVOS(List<ECObjDataVO> list) {
        List<CommonIteratorVO> commonIteratorVOList = new ArrayList<>();
        for (ECObjDataVO ecObjData : list) {
            CommonIteratorVO commonIteratorVO = new CommonIteratorVO();
            commonIteratorVO.setId(String.valueOf(ecObjData.getOid()));
            commonIteratorVO.setTypeDefName(ecObjData.getOtype());
            commonIteratorVO.setChangePolicy("Change");
            commonIteratorVOList.add(commonIteratorVO);
        }
        return typlmIterationService.batchNewVersionWithPolicy(commonIteratorVOList);
    }

    /**
     * 添加物料至变更后
     *
     * @param entityList
     * @param oid
     */
    private void addObjectTOChgAfter(List<ECObjDTO> entityList, BigInteger oid) {
        this.tyChangeCheckService.checkChangeObjectAfterCheck(entityList);
        List<ChgActivityDO> ecaList = this.typlmChgNoticeActivityLinkMapper.queryECAByECNId(oid);
        if (CollUtil.isEmpty(ecaList)) {
            return;
        }
        ChgActivityDO chgActivityDO = ecaList.get(0);
        IdentifierEntity identifierEntity = new IdentifierEntity(chgActivityDO.getOid(), chgActivityDO.getOtype());
        this.changeObjectLinkExtService.createECObjDataLinkList(identifierEntity, entityList, Boolean.FALSE);
    }

    //校验变更前对象
    public List<String> checkLifecycleStageKey(String number, String status, String typeDefName, List<String> errorList) {
        StringBuffer sb = new StringBuffer();
        if (!"RELEASED".equals(status)) {
            errorList.add(sb.append("编码为").append(number).append("的").append(typeDefName).toString());

        }
        return errorList;
    }

    //校验变更对象是否检出
    public String judgeIsCheckOut(String oid, String otype, String number, String typeDefName, StringBuffer buffer) {
        String tableName = "";
        if (RTPlmConstant.PART_TYPE.equals(otype)) {
            tableName = RTPlmConstant.PART_TABLE;
        }
        if (RTPlmConstant.DOC_TYPE.equals(otype)) {
            tableName = RTPlmConstant.DOC_TABLE;
        }
        if (RTPlmConstant.CADDOC_TYPE.equals(otype)) {
            tableName = RTPlmConstant.CADDOC_TABLE;
        }
        int i = this.rtChangeMapper.judgeCheckOut(tableName, oid);
        if (i == 1) {
            buffer.append("编码为").append(number).append("的").append(typeDefName).append("已被检出; \n");
        }
        return buffer.toString();
    }

    private String converSoureListInputAttr(String partNumber, String factory, String supplier) {
        JSONObject tempJson = new JSONObject();
        tempJson.put("MATNR", partNumber);
        tempJson.put("WERKS", factory);
        tempJson.put("LIFNR", supplier);
        tempJson.put("ZFLAG", "");
        tempJson.put("NOTKZ", "");
        ArrayList list = new ArrayList();
        list.add(tempJson);
        JSONObject tempJson2 = new JSONObject();
        tempJson2.put("item", list);
        JSONObject sourceJson = new JSONObject();
        sourceJson.put("IT_TAB", tempJson2);
        return sourceJson.toString();
    }

    public List<String> getUserDepartMent(BigInteger oid) {
        List list = new ArrayList<>();
        PrincipalEntity principalEntity = new PrincipalEntity(oid, TableTypeConstrant.TY_USER_OTYPE);
        List<PrincipalEntity> outParent = typlmPrincipalService.getOneOutParentOrg(principalEntity);
        typlmOrgService.dealOrgParentPath(outParent);
        if (CollUtil.isEmpty(outParent)) {
            return list;
        }
        for (PrincipalEntity entity : outParent) {
            if (entity instanceof OrgDO) {
                OrgDO orgDO = (OrgDO) entity;
                String name = orgDO.getName();
                list.add(name);
            }
        }
        return list;
    }
}